v1.0 Initial commit of project
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
pub/data/devices/*/documents/*
|
||||||
|
pub/data/devices/*/firmware/*
|
||||||
|
.idea/*
|
||||||
|
composer.*
|
||||||
|
pub/config.php
|
||||||
202
LICENSE
Normal file
202
LICENSE
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright 2025 Marco Mooij
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
748
pub/api/classes/API.php
Normal file
748
pub/api/classes/API.php
Normal file
@@ -0,0 +1,748 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
class API
|
||||||
|
{
|
||||||
|
public $conn;
|
||||||
|
|
||||||
|
# The user uuid that requested the API
|
||||||
|
protected $user_uuid;
|
||||||
|
|
||||||
|
# $user_type is either an API call (api) or an call from the frontend (frontend)
|
||||||
|
protected $user_type;
|
||||||
|
|
||||||
|
# Either GET POST PUT or DELETE
|
||||||
|
public $request_method;
|
||||||
|
|
||||||
|
protected $content_type;
|
||||||
|
|
||||||
|
# The original posted data to the API, this data is NOT sanitized and validated, never use this data for queries!
|
||||||
|
public $postedData;
|
||||||
|
|
||||||
|
# The validated and sanitized data can be uses for the API actions
|
||||||
|
public $data;
|
||||||
|
|
||||||
|
# The permission of the user to check if the action is allowed.
|
||||||
|
public $permissions;
|
||||||
|
|
||||||
|
# The return url that the frontend request will forward to after the api call is done. if set to false it will only output
|
||||||
|
# the json response with an http code. API calls always respond with json. $return_url can be set to supply the form with an input
|
||||||
|
# with the name _return and value of the url to return to.
|
||||||
|
public $return_url;
|
||||||
|
|
||||||
|
# Required fields & optional fields set by the API actions. This is an array like:
|
||||||
|
# Example:
|
||||||
|
# 'user_uuid' => ['type' => 'string', 'min' => 5, 'max' => 36],
|
||||||
|
# 'user_enabled' => ['type' => 'int', 'min' => 0, 'max' => 99],
|
||||||
|
# 'user_active' => ['type' => 'enum', 'values' => ['active', 'inactive', 'banned']],
|
||||||
|
# 'user_email' => ['type' => 'string', 'format' => 'email'],
|
||||||
|
private $requiredFields = [];
|
||||||
|
private $optionalFields = [];
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
# Setup Database connection
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/bin/php/db_connect.php';
|
||||||
|
$this->conn = $GLOBALS['conn'];
|
||||||
|
|
||||||
|
if (!empty($_SESSION['user']['user_uuid'])) {
|
||||||
|
$this->InitUserTypeFrontend();
|
||||||
|
} else {
|
||||||
|
$this->InitUserTypeAPI();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->return_url = $this->setReturnUrl();
|
||||||
|
|
||||||
|
# user_uuid will be set if the user is authorized
|
||||||
|
if (!$this->user_uuid) {
|
||||||
|
$this->apiOutput(401, ['error' => 'Unauthorized']);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Only allow POST, GET, PUT and DELETE
|
||||||
|
if (!$this->checkRequestMethod()) {
|
||||||
|
$this->apiOutput(405, ['error' => 'Method not allowed']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!$this->checkContentType()) {
|
||||||
|
$this->apiOutput(400, ['error' => 'Unsupported Content-Type.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->content_type === 'application/json') {
|
||||||
|
if (!$this->checkJson()) {
|
||||||
|
$this->apiOutput(400, ['error' => 'Invalid JSON format']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable builder input for non-GET requests to prevent potential SQL injection vulnerabilities.
|
||||||
|
// Also disable the builder for users with the 'frontend' user type as an extra security measure.
|
||||||
|
// The builder should only be active for API users making GET requests.
|
||||||
|
// When building a frontend page, you can still programmatically construct a builder array
|
||||||
|
// and set it via $_GET like so after the API class creation:
|
||||||
|
// $_GET['builder'] = [1 => ['where' => [0 => 'permission_uuid', 1 => $permission_uuid]]];
|
||||||
|
if ($this->request_method !== 'GET' || $this->user_type === 'frontend') {
|
||||||
|
$this->disableBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
# This converts the posted data if needed to an PHP array
|
||||||
|
$this->postedData = $this->processPostedData();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function InitUserTypeFrontend()
|
||||||
|
{
|
||||||
|
$this->user_uuid = $_SESSION['user']['user_uuid'];
|
||||||
|
$this->user_type = 'frontend';
|
||||||
|
|
||||||
|
# Load the locale for the user, this is used for the return message in the frontend and other globalFunctions.
|
||||||
|
include_once $_SERVER['DOCUMENT_ROOT'] . '/bin/php/Functions/globalFunctions.php';
|
||||||
|
$locale = getPreferredLocale();
|
||||||
|
global $translations;
|
||||||
|
$translations = require $_SERVER['DOCUMENT_ROOT'] . "/bin/locales/{$locale}.php";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function RecursiveDeleteFolder($folderPath): bool
|
||||||
|
{
|
||||||
|
// Check if the folder exists
|
||||||
|
if (!is_dir($folderPath)) {
|
||||||
|
$this->apiOutput(500, ['error' => 'directory not found: ' . $folderPath]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all files and folders in the directory
|
||||||
|
$items = array_diff(scandir($folderPath), array('.', '..'));
|
||||||
|
|
||||||
|
// Loop through each item
|
||||||
|
foreach ($items as $item) {
|
||||||
|
|
||||||
|
$itemPath = $folderPath . DIRECTORY_SEPARATOR . $item;
|
||||||
|
|
||||||
|
if (is_dir($itemPath)) {
|
||||||
|
if (!$this->RecursiveDeleteFolder($itemPath)) {
|
||||||
|
$this->apiOutput(500, ['error' => "Unable to remove directory: $itemPath"]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!unlink($itemPath)) {
|
||||||
|
$this->apiOutput(500, ['error' => "Unable to delete file: $itemPath"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the main folder after all contents are gone
|
||||||
|
if (!rmdir($folderPath)) {
|
||||||
|
$this->apiOutput(500, ['error' => "Unable to remove directory: $folderPath"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function InitUserTypeAPI()
|
||||||
|
{
|
||||||
|
$this->user_type = 'api';
|
||||||
|
|
||||||
|
$headers = getallheaders();
|
||||||
|
$authHeader = $headers['Authorization'] ?? '';
|
||||||
|
|
||||||
|
if (!preg_match('/^Bearer\s+(.+)$/', $authHeader, $matches)) {
|
||||||
|
$this->apiOutput(401, ['error' => 'Unauthorized, missing bearer token.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$bearerToken = trim($matches[1]);
|
||||||
|
|
||||||
|
if (!preg_match('/^[a-f0-9\-]{36}\.[a-f0-9]{64}$/i', $bearerToken)) {
|
||||||
|
$this->apiOutput(401, ['error' => 'Unauthorized, invalid token format.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
[$tokenId, $tokenSecret] = explode('.', $bearerToken, 2);
|
||||||
|
|
||||||
|
$this->user_uuid = $this->validateToken($tokenId, $tokenSecret);
|
||||||
|
|
||||||
|
if ($this->user_uuid === false) {
|
||||||
|
$this->apiOutput(401, ['error' => 'Unauthorized, invalid or expired token.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$api_token_last_used_timestamp = time();
|
||||||
|
$stmt = $this->conn->prepare("UPDATE vc_api_tokens SET api_token_last_used_timestamp = ? WHERE api_token_uuid = ?");
|
||||||
|
$stmt->bind_param("is", $api_token_last_used_timestamp, $tokenId);
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateSingleData($value, $rules)
|
||||||
|
{
|
||||||
|
if (!$this->validateField($value, $rules)) {
|
||||||
|
$this->apiOutput(400, ['error' => "Invalid value: $value"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->sanitizeData($value, $rules['type']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateData($requiredFields, $optionalFields = [])
|
||||||
|
{
|
||||||
|
$inputData = $this->postedData;
|
||||||
|
|
||||||
|
$this->requiredFields = $requiredFields;
|
||||||
|
$this->optionalFields = $optionalFields;
|
||||||
|
$sanitizedData = [];
|
||||||
|
|
||||||
|
foreach ($this->requiredFields as $field => $rules) {
|
||||||
|
|
||||||
|
if (!array_key_exists($field, $inputData)) {
|
||||||
|
$this->apiOutput(400, ['error' => "Missing required field: $field"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = $inputData[$field];
|
||||||
|
|
||||||
|
if (!$this->validateField($value, $rules)) {
|
||||||
|
$this->apiOutput(400, ['error' => "Invalid value for $field"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sanitizedData[$field] = $this->sanitizeData($value, $rules['type']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Check optional fields
|
||||||
|
foreach ($this->optionalFields as $field => $rules) {
|
||||||
|
if (isset($inputData[$field])) {
|
||||||
|
$value = $inputData[$field];
|
||||||
|
|
||||||
|
if (!$this->validateField($value, $rules)) {
|
||||||
|
$this->apiOutput(422, ['error' => "Invalid value for optional field: $field"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sanitizedData[$field] = $this->sanitizeData($value, $rules['type']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_GET['builder']) && is_array($_GET['builder'])) {
|
||||||
|
foreach ($_GET['builder'] as $builder) {
|
||||||
|
if (!isset($builder['where']) || count($builder['where']) !== 2) {
|
||||||
|
continue; // skip invalid builders
|
||||||
|
}
|
||||||
|
|
||||||
|
$field = $builder['where'][0];
|
||||||
|
$value = $builder['where'][1];
|
||||||
|
|
||||||
|
// Check if the field is allowed (in required or optional)
|
||||||
|
$rules = $requiredFields[$field] ?? $optionalFields[$field] ?? null;
|
||||||
|
if (!$rules) {
|
||||||
|
$this->apiOutput(403, ['error' => "Field not allowed in query: $field"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate and sanitize
|
||||||
|
if (!$this->validateField($value, $rules)) {
|
||||||
|
$this->apiOutput(422, ['error' => "Invalid value for builder field: $field"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sanitizedData[$field] = $this->sanitizeData($value, $rules['type']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->data = $sanitizedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isValidLength($value, $rules)
|
||||||
|
{
|
||||||
|
$length = strlen($value);
|
||||||
|
if (isset($rules['min']) && $length < $rules['min']) return false;
|
||||||
|
if (isset($rules['max']) && $length > $rules['max']) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isValidNumberRange($value, $rules)
|
||||||
|
{
|
||||||
|
if (isset($rules['min']) && $value < $rules['min']) return false;
|
||||||
|
if (isset($rules['max']) && $value > $rules['max']) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validateField($value, $rules)
|
||||||
|
{
|
||||||
|
switch ($rules['type']) {
|
||||||
|
case 'string':
|
||||||
|
if (!is_string($value)) return false;
|
||||||
|
return $this->isValidLength($value, $rules);
|
||||||
|
case 'slugify':
|
||||||
|
if (!is_string($value) || !preg_match('/^[a-z0-9]+(-[a-z0-9]+)*$/', $value)) return false;
|
||||||
|
return $this->isValidLength($value, $rules);
|
||||||
|
|
||||||
|
case 'boolean':
|
||||||
|
if (is_bool($value)) return true;
|
||||||
|
|
||||||
|
if (is_string($value)) {
|
||||||
|
$value = strtolower($value);
|
||||||
|
return $value === 'true' || $value === 'false' || $value === '1' || $value === '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_int($value)) {
|
||||||
|
return $value === 1 || $value === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case 'email':
|
||||||
|
if (!is_string($value)) return false;
|
||||||
|
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) return false;
|
||||||
|
return $this->isValidLength($value, $rules);
|
||||||
|
|
||||||
|
case 'password':
|
||||||
|
if (!is_string($value)) return false;
|
||||||
|
return $this->isValidLength($value, $rules);
|
||||||
|
|
||||||
|
case 'html':
|
||||||
|
if (!is_string($value)) return false;
|
||||||
|
return $this->isValidLength($value, $rules);
|
||||||
|
|
||||||
|
case 'int':
|
||||||
|
if (!is_int($value) && !ctype_digit($value)) return false;
|
||||||
|
$value = (int)$value;
|
||||||
|
return $this->isValidNumberRange($value, $rules);
|
||||||
|
|
||||||
|
case 'float':
|
||||||
|
// Accept floats or numeric strings
|
||||||
|
if (!is_float($value) && !is_numeric($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$value = (float)$value;
|
||||||
|
return $this->isValidNumberRange($value, $rules);
|
||||||
|
|
||||||
|
case 'timestamp':
|
||||||
|
if (is_null($value)) return true;
|
||||||
|
if (!is_int($value) && !ctype_digit($value)) return false;
|
||||||
|
$value = (int)$value;
|
||||||
|
if ($value < 0) return false;
|
||||||
|
$min = $rules['min'] ?? 1;
|
||||||
|
$max = $rules['max'] ?? 4102444800;
|
||||||
|
return $value >= $min && $value <= $max;
|
||||||
|
|
||||||
|
case 'enum':
|
||||||
|
if (!isset($rules['values']) || !in_array($value, $rules['values'], true)) return false;
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case 'uuid':
|
||||||
|
if (!is_string($value)) return false;
|
||||||
|
return preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i', $value);
|
||||||
|
|
||||||
|
case 'base64':
|
||||||
|
if (!is_string($value)) return false;
|
||||||
|
return base64_encode(base64_decode($value, true)) === $value;
|
||||||
|
|
||||||
|
case 'uuid':
|
||||||
|
if (!is_string($value)) return false;
|
||||||
|
return preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i', $value);
|
||||||
|
|
||||||
|
case 'json':
|
||||||
|
if (!is_string($value)) return false;
|
||||||
|
json_decode($value);
|
||||||
|
return json_last_error() === JSON_ERROR_NONE;
|
||||||
|
|
||||||
|
case 'array':
|
||||||
|
if (!is_array($value)) return false;
|
||||||
|
return $value;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sanitizeData($value, $type)
|
||||||
|
{
|
||||||
|
switch ($type) {
|
||||||
|
case 'string':
|
||||||
|
case 'enum':
|
||||||
|
case 'uuid':
|
||||||
|
// Remove HTML tags and encode special characters
|
||||||
|
return htmlspecialchars(strip_tags($value), ENT_QUOTES, 'UTF-8');
|
||||||
|
|
||||||
|
case 'email':
|
||||||
|
// Remove illegal characters from email address
|
||||||
|
return filter_var($value, FILTER_SANITIZE_EMAIL);
|
||||||
|
|
||||||
|
case 'password':
|
||||||
|
// Passwords may contain special characters; just trim spaces
|
||||||
|
return trim($value);
|
||||||
|
|
||||||
|
case 'html':
|
||||||
|
// Allow safe HTML, you can customize allowed tags
|
||||||
|
return strip_tags($value, '<b><i><u><strong><em><p><br>');
|
||||||
|
|
||||||
|
case 'int':
|
||||||
|
// Remove anything that's not a number
|
||||||
|
return filter_var($value, FILTER_SANITIZE_NUMBER_INT);
|
||||||
|
|
||||||
|
case 'base64':
|
||||||
|
// Only allow base64 valid characters
|
||||||
|
return preg_replace('/[^a-zA-Z0-9\/\+=]/', '', $value);
|
||||||
|
|
||||||
|
case 'boolean':
|
||||||
|
if (is_string($value)) {
|
||||||
|
$value = strtolower(trim($value));
|
||||||
|
return in_array($value, ['true', '1'], true) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (bool)$value;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Return as-is if unknown type
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkPermissions($permission_name, $accessRightsRequired, $returnBoolean = false)
|
||||||
|
{
|
||||||
|
$accessLevels = [
|
||||||
|
'NA' => 0, // No Access
|
||||||
|
'RO' => 1, // Read Only
|
||||||
|
'RW' => 2, // Read Write
|
||||||
|
];
|
||||||
|
$query = "SELECT
|
||||||
|
vc_permissions.permission_name,
|
||||||
|
vc_user_group_permissions_portal.permission_value
|
||||||
|
FROM vc_user_group_permissions_portal
|
||||||
|
INNER JOIN vc_permissions ON vc_user_group_permissions_portal.permission_uuid =vc_permissions.permission_uuid
|
||||||
|
INNER JOIN vc_users ON vc_user_group_permissions_portal.user_group_uuid = vc_users.user_group_uuid
|
||||||
|
WHERE user_uuid = ? AND permission_name = ?";
|
||||||
|
|
||||||
|
|
||||||
|
$stmt = $this->conn->prepare($query);
|
||||||
|
$stmt->bind_param("ss", $this->user_uuid, $permission_name);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result()->fetch_assoc();
|
||||||
|
|
||||||
|
if (!$result) {
|
||||||
|
if ($returnBoolean) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->apiOutput(500, ['error' => 'Did not find permission required']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$userAccess = $result['permission_value'];
|
||||||
|
|
||||||
|
if (!isset($accessLevels[$userAccess]) || !isset($accessLevels[$accessRightsRequired])) {
|
||||||
|
if ($returnBoolean) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->apiOutput(500, ['error' => 'Server error.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare user's access level with the required access level
|
||||||
|
if ($accessLevels[$userAccess] < $accessLevels[$accessRightsRequired]) {
|
||||||
|
if ($returnBoolean) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->apiOutput(403, ['error' => 'Permission denied. You do not have the required access level.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($returnBoolean) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setReturnUrl()
|
||||||
|
{
|
||||||
|
if ($this->user_type !== 'frontend') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$method = $_SERVER['REQUEST_METHOD'];
|
||||||
|
|
||||||
|
if ($method === 'POST' && isset($_POST['_return'])) {
|
||||||
|
return $_POST['_return'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($method === 'PUT') {
|
||||||
|
parse_str(file_get_contents("php://input"), $putData);
|
||||||
|
if (isset($putData['_return'])) {
|
||||||
|
return $putData['_return'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($method === 'GET') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_SERVER['HTTP_REFERER'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function checkRequestMethod()
|
||||||
|
{
|
||||||
|
$allowedMethods = ['GET', 'POST', 'PUT', 'DELETE'];
|
||||||
|
$method = $_SERVER['REQUEST_METHOD'] ?? '';
|
||||||
|
|
||||||
|
if (!in_array($method, $allowedMethods)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Since browser doesnt allow DELETE or PUTs from the frontend forms (apart from some javascript/ajax fuckery)
|
||||||
|
# we need to check the _method POST value.
|
||||||
|
if ($this->user_type === 'frontend' && $method === 'POST' && isset($_POST['_method'])) {
|
||||||
|
$overrideMethod = strtoupper($_POST['_method']);
|
||||||
|
|
||||||
|
if (in_array($overrideMethod, ['PUT', 'DELETE'])) {
|
||||||
|
$this->request_method = $overrideMethod;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->request_method = $method;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function checkJson()
|
||||||
|
{
|
||||||
|
$rawInput = file_get_contents('php://input');
|
||||||
|
if (empty($rawInput)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
json_decode($rawInput, true);
|
||||||
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function processPostedData()
|
||||||
|
{
|
||||||
|
if ($this->user_type === 'api') {
|
||||||
|
return json_decode(file_get_contents("php://input"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($this->request_method) {
|
||||||
|
case 'GET':
|
||||||
|
return $_GET;
|
||||||
|
case 'POST':
|
||||||
|
return $_POST;
|
||||||
|
case 'PUT':
|
||||||
|
case 'DELETE':
|
||||||
|
# When an image is uploaded from the front end the data needs to be specified its in $_POST and not $_FILES
|
||||||
|
if ($this->content_type === 'multipart/form-data') {
|
||||||
|
return $_POST;
|
||||||
|
} else {
|
||||||
|
parse_str(file_get_contents("php://input"), $data);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function validateToken(string $tokenId, string $tokenSecret)
|
||||||
|
{
|
||||||
|
$stmt = $this->conn->prepare("SELECT user_uuid, api_token FROM vc_api_tokens WHERE api_token_uuid = ? AND api_token_expiration_timestamp > UNIX_TIMESTAMP()");
|
||||||
|
$stmt->bind_param("s", $tokenId);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$row = $stmt->get_result()->fetch_assoc();
|
||||||
|
|
||||||
|
if (!$row) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!password_verify($tokenSecret, $row['api_token'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $row['user_uuid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function checkContentType()
|
||||||
|
{
|
||||||
|
# api will need to post with an application/json type Content type.
|
||||||
|
# frontend will post with application/x-www-form-urlencoded content type but also is capable of application/json
|
||||||
|
# frontend can also post multipart/form-data
|
||||||
|
# GET requests dont have an content type
|
||||||
|
|
||||||
|
$contentType = $_SERVER['CONTENT_TYPE'] ?? '';
|
||||||
|
|
||||||
|
if ($this->request_method === 'GET') {
|
||||||
|
$this->content_type = '';
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->user_type === 'api') {
|
||||||
|
$this->content_type = 'application/json';
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($contentType, 'application/json') !== false) {
|
||||||
|
$this->content_type = 'application/json';
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($contentType, 'application/x-www-form-urlencoded') !== false) {
|
||||||
|
$this->content_type = 'application/x-www-form-urlencoded';
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($contentType, 'multipart/form-data') !== false) {
|
||||||
|
$this->content_type = 'multipart/form-data';
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserUuid()
|
||||||
|
{
|
||||||
|
return $this->user_uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function apiOutput($code = 200, $data = [], $frontendMessage = false)
|
||||||
|
{
|
||||||
|
if ($this->user_type === 'api') {
|
||||||
|
http_response_code($code);
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
if ($code === 200) {
|
||||||
|
echo json_encode(reset($data));
|
||||||
|
} else {
|
||||||
|
echo json_encode($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($this->user_type === 'frontend') {
|
||||||
|
if (in_array($this->request_method, ['POST', 'PUT', 'DELETE'])) {
|
||||||
|
http_response_code($code);
|
||||||
|
|
||||||
|
if ($this->return_url) { # sometimes the PUT doesnt need an return or response set (Think of js actions to api from frontend)
|
||||||
|
$_SESSION['response'] = json_encode($data);
|
||||||
|
|
||||||
|
# When a request is successfull the api will recieve the data, the frontend needs a friendly message
|
||||||
|
if ($frontendMessage) {
|
||||||
|
$_SESSION['response'] = json_encode([key($data) => __($frontendMessage)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Location: ' . $this->return_url);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
echo json_encode($data);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareStatement($query)
|
||||||
|
{
|
||||||
|
// Enable MySQLi to throw exceptions on errors
|
||||||
|
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$stmt = $this->conn->prepare($query);
|
||||||
|
|
||||||
|
} catch (mysqli_sql_exception $e) {
|
||||||
|
// If an error occurs during prepare, catch it and return a proper response
|
||||||
|
$this->apiOutput(500, ['error' => 'Database error: ' . $e->getMessage()]);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $stmt;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function executeStatement($stmt)
|
||||||
|
{
|
||||||
|
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$stmt->execute();
|
||||||
|
return true;
|
||||||
|
} catch (mysqli_sql_exception $e) {
|
||||||
|
if ($e->getCode() === 1451) {
|
||||||
|
$this->apiOutput(409, ['error' => 'Cannot delete record: dependent data exists.']);
|
||||||
|
} else {
|
||||||
|
$this->apiOutput(500, ['error' => 'Database error: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isSuperuser()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM vc_users WHERE vc_users.user_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('s', $this->user_uuid);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
$user_data = $result->fetch_assoc();
|
||||||
|
if ($user_data['user_email'] == 'superuser') {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buildDynamicQuery(string $tableName): array
|
||||||
|
{
|
||||||
|
$baseQuery = "SELECT * FROM " . $tableName;
|
||||||
|
$whereClauses = [];
|
||||||
|
$types = '';
|
||||||
|
$values = [];
|
||||||
|
|
||||||
|
if (!isset($_GET['builder']) || !is_array($_GET['builder'])) {
|
||||||
|
return [$baseQuery, $types, $values];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($_GET['builder'] as $builder) {
|
||||||
|
if (!isset($builder['where']) || !is_array($builder['where']) || count($builder['where']) !== 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$column = $builder['where'][0];
|
||||||
|
$value = $builder['where'][1];
|
||||||
|
|
||||||
|
$whereClauses[] = "$column = ?";
|
||||||
|
$types .= 's';
|
||||||
|
$values[] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($whereClauses)) {
|
||||||
|
$baseQuery .= " WHERE " . implode(" AND ", $whereClauses);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [$baseQuery, $types, $values];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function generalGetFunction($query, $types, $params, $returnBoolean, $itemName)
|
||||||
|
{
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
|
||||||
|
if (!empty($params)) {
|
||||||
|
$stmt->bind_param($types, ...$params);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
if ($result->num_rows === 0) {
|
||||||
|
if (!$returnBoolean) {
|
||||||
|
$this->apiOutput(404, ['error' => $itemName . ' not found.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$tokens = [];
|
||||||
|
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$tokens[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disableBuilder(): void
|
||||||
|
{
|
||||||
|
if (isset($_GET['builder'])) {
|
||||||
|
unset($_GET['builder']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
108
pub/api/classes/API_apitoken.php
Normal file
108
pub/api/classes/API_apitoken.php
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_apitoken extends API
|
||||||
|
{
|
||||||
|
public function getTokens()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM vc_api_tokens WHERE vc_api_tokens.user_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('s', $this->data['user_uuid']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
$tokens = [];
|
||||||
|
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$tokens[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createNewToken()
|
||||||
|
{
|
||||||
|
|
||||||
|
$api_token = bin2hex(random_bytes(64 / 2));
|
||||||
|
|
||||||
|
|
||||||
|
$api_token_hash = password_hash($api_token, PASSWORD_BCRYPT, ["cost" => 12]);
|
||||||
|
$api_token_expiration_timestamp = strtotime('+1 year');
|
||||||
|
$query = "INSERT INTO vc_api_tokens (api_token_uuid, user_uuid, api_token, api_token_expiration_timestamp, api_token_created_timestamp) VALUES (UUID(), ?, ?, ?, ?)";
|
||||||
|
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
|
||||||
|
$stmt->bind_param('ssii', $this->data['user_uuid'], $api_token_hash, $api_token_expiration_timestamp, time());
|
||||||
|
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$result = $this->getNewToken();
|
||||||
|
$_SESSION['tmp_api_token'] = $api_token;
|
||||||
|
|
||||||
|
if ($result->num_rows > 0) {
|
||||||
|
$api_token_data = $result->fetch_assoc();
|
||||||
|
|
||||||
|
$_SESSION['tmp_api_token'] = $api_token_data['api_token_uuid'] . '.' . $api_token;
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => $api_token_data], 'api_token_created');
|
||||||
|
} else {
|
||||||
|
$this->apiOutput(500, ['error' => 'Something went wrong creating the token on the server.'], 'error_contact_support');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNewToken()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM vc_api_tokens WHERE user_uuid = ? ORDER BY api_token_created_timestamp DESC LIMIT 1";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('s', $this->data['user_uuid']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
return $stmt->get_result();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getToken()
|
||||||
|
{
|
||||||
|
$query = "SELECT vc_users.user_email, vc_users.user_uuid FROM vc_api_tokens INNER JOIN vc_users ON vc_api_tokens.user_uuid = vc_users.user_uuid WHERE api_token_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('s', $this->data['api_token_uuid']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
if ($result->num_rows === 0) {
|
||||||
|
$this->apiOutput(404, ['error' => 'API token not found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$api_token_data = $result->fetch_assoc();
|
||||||
|
|
||||||
|
return $api_token_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteToken()
|
||||||
|
{
|
||||||
|
$query = "DELETE FROM vc_api_tokens WHERE api_token_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('s', $this->data['api_token_uuid']);
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'API token deleted successfully.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function revokeToken()
|
||||||
|
{
|
||||||
|
|
||||||
|
$api_token_revoked = ($this->data['api_token_revoked']) ? 1 : 0;
|
||||||
|
|
||||||
|
$query = "UPDATE vc_api_tokens SET api_token_revoked = ? WHERE api_token_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('is', $api_token_revoked, $this->data['api_token_uuid']);
|
||||||
|
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'API token ' . ($api_token_revoked ? 're' : 'en') . 'voked successfully.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
pub/api/classes/API_companies.php
Normal file
20
pub/api/classes/API_companies.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_companies extends API
|
||||||
|
{
|
||||||
|
public function updateCompanyState()
|
||||||
|
{
|
||||||
|
$query = "UPDATE companies SET company_state = ? WHERE company_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('ss', $this->data['company_state'], $this->data['company_uuid']);
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'company state successfully updated']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
130
pub/api/classes/API_devices.php
Normal file
130
pub/api/classes/API_devices.php
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use api\classes\imageProcessor;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_devices extends API
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getDevices($returnBoolean = false)
|
||||||
|
{
|
||||||
|
list($query, $types, $params) = $this->buildDynamicQuery('vc_devices');
|
||||||
|
|
||||||
|
$items = $this->generalGetFunction($query, $types, $params, $returnBoolean, 'Device');
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDeviceSlugify()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM vc_devices WHERE device_slugify = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("s", $this->data['device_slugify']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
return $stmt->get_result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createDeviceImage($imageRestrictions)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
# Main image
|
||||||
|
$imageProcessor = new imageProcessor('device_image');
|
||||||
|
$imageProcessor->imageRestrictions = $imageRestrictions;
|
||||||
|
$imageProcessor->validateAndProcess();
|
||||||
|
$ImageData = $imageProcessor->returnBase64image();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->apiOutput(401, ['error' => 'Error: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ImageData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createDevice()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (isset($this->data['device_image'])) {
|
||||||
|
$query = "INSERT INTO vc_devices (device_uuid, device_vendor_uuid, device_type, device_name, device_slugify, device_enabled, device_notes, device_eol, device_extensions, device_extra, device_create_timestamp, device_image, device_image_thumbnail)
|
||||||
|
VALUES (UUID(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("ssssisississ", $this->data['device_vendor_uuid'], $this->data['device_type'], $this->data['device_name'], $this->data['device_slugify'], $this->data['device_enabled'], $this->data['device_notes'], $this->data['device_eol'], $this->data['device_extensions'], $this->data['device_extra'], time(), $this->data['device_image'], $this->data['device_image_thumbnail']);
|
||||||
|
} else {
|
||||||
|
$query = "INSERT INTO vc_devices (device_uuid, device_vendor_uuid, device_type, device_name, device_slugify, device_enabled, device_notes, device_eol, device_extensions, device_extra, device_create_timestamp)
|
||||||
|
VALUES (UUID(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("ssssisissi", $this->data['device_vendor_uuid'], $this->data['device_type'], $this->data['device_name'], $this->data['device_slugify'], $this->data['device_enabled'], $this->data['device_notes'], $this->data['device_eol'], $this->data['device_extensions'], $this->data['device_extra'], time());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
$result = $this->getDeviceSlugify();
|
||||||
|
if ($result->num_rows === 0) {
|
||||||
|
$this->apiOutput(500, ['error' => 'Something went wrong creating the device.'], 'error_contact_support');
|
||||||
|
}
|
||||||
|
|
||||||
|
$createDirsFailed = false;
|
||||||
|
$dirsToCreate = array(
|
||||||
|
$_SERVER['DOCUMENT_ROOT'] . "/data/devices/" . $this->data['device_slugify'],
|
||||||
|
$_SERVER['DOCUMENT_ROOT'] . "/data/devices/" . $this->data['device_slugify'] . "/firmware",
|
||||||
|
$_SERVER['DOCUMENT_ROOT'] . "/data/devices/" . $this->data['device_slugify'] . "/documents"
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($dirsToCreate as $dir) {
|
||||||
|
if (!file_exists($dir)) {
|
||||||
|
if (!mkdir($dir)) {
|
||||||
|
$createDirsFailed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($createDirsFailed) {
|
||||||
|
$this->apiOutput(500, ['error' => 'Something went wrong creating the device on the server.'], 'error_contact_support');
|
||||||
|
}
|
||||||
|
|
||||||
|
$platform_data = $result->fetch_assoc();
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => $platform_data], 'item_added');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateDevice()
|
||||||
|
{
|
||||||
|
if (isset($this->data['device_image'])) {
|
||||||
|
$query = "UPDATE vc_devices SET device_modified_timestamp = ?, device_vendor_uuid = ?, device_name = ?, device_enabled = ?, device_notes = ?, device_eol = ?, device_extensions = ?, device_extra = ?, device_image = ?, device_image_thumbnail = ? WHERE device_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("issisisssss", time(), $this->data['device_vendor_uuid'], $this->data['device_name'], $this->data['device_enabled'], $this->data['device_notes'], $this->data['device_eol'], $this->data['device_extensions'], $this->data['device_extra'], $this->data['device_image'], $this->data['device_image_thumbnail'], $this->data['device_uuid']);
|
||||||
|
} else {
|
||||||
|
$query = "UPDATE vc_devices SET device_modified_timestamp = ?, device_vendor_uuid = ?, device_name = ?, device_enabled = ?, device_notes = ?, device_eol = ?, device_extensions = ?, device_extra = ? WHERE device_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("issisisss", time(), $this->data['device_vendor_uuid'], $this->data['device_name'], $this->data['device_enabled'], $this->data['device_notes'], $this->data['device_eol'], $this->data['device_extensions'], $this->data['device_extra'], $this->data['device_uuid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'Device updated successfully.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteDevice()
|
||||||
|
{
|
||||||
|
# check if the device exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'device_uuid', 1 => $this->data['device_uuid']]]];
|
||||||
|
$device = $this->getDevices()[0];
|
||||||
|
|
||||||
|
# remove from database
|
||||||
|
$query = "DELETE FROM vc_devices WHERE device_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("s", $device['device_uuid']);
|
||||||
|
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
# Delete the device data folder.
|
||||||
|
$dirsToDelete = $_SERVER['DOCUMENT_ROOT'] . "/data/devices/" . $device['device_slugify'];
|
||||||
|
$this->RecursiveDeleteFolder($dirsToDelete);
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'Device removed successfully.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
478
pub/api/classes/API_inserve.php
Normal file
478
pub/api/classes/API_inserve.php
Normal file
@@ -0,0 +1,478 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_inserve extends API
|
||||||
|
{
|
||||||
|
|
||||||
|
private $inserve_url;
|
||||||
|
|
||||||
|
private $inserve_token;
|
||||||
|
|
||||||
|
public $inserve_source_uuid;
|
||||||
|
|
||||||
|
private $ch;
|
||||||
|
public $httpCode = false;
|
||||||
|
|
||||||
|
public $response = false;
|
||||||
|
|
||||||
|
private $cloudDistrubutor = 'digistate-servers';
|
||||||
|
|
||||||
|
public function setupConnection()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM system_sources WHERE source_name = 'inserve'";
|
||||||
|
$result = $this->conn->query($query)->fetch_assoc();
|
||||||
|
|
||||||
|
$this->inserve_url = $result['source_url'];
|
||||||
|
$this->inserve_token = $result['source_auth_token'];
|
||||||
|
$this->inserve_source_uuid = $result['source_uuid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execCurl()
|
||||||
|
{
|
||||||
|
$this->response = curl_exec($this->ch);
|
||||||
|
$this->httpCode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
|
||||||
|
|
||||||
|
curl_close($this->ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function returnResponse()
|
||||||
|
{
|
||||||
|
$this->apiOutput($this->httpCode, json_decode($this->response, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function authMe()
|
||||||
|
{
|
||||||
|
$this->ch = curl_init($this->inserve_url . 'auth/me');
|
||||||
|
curl_setopt_array($this->ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
"X-Api-Key: $this->inserve_token",
|
||||||
|
"Accept: application/json"
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
$this->execCurl();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLinkedCompanies()
|
||||||
|
{
|
||||||
|
$this->ch = curl_init($this->inserve_url . 'cloud-distributors/digistate-servers/companies');
|
||||||
|
curl_setopt_array($this->ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
"X-Api-Key: $this->inserve_token",
|
||||||
|
"Accept: application/json"
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
$this->execCurl();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function companies($page)
|
||||||
|
{
|
||||||
|
// Build array the way the API expects
|
||||||
|
$params = [
|
||||||
|
'b' => [
|
||||||
|
['orderBy' => ['name', 'ASC']],
|
||||||
|
['orderBy' => ['id', 'DESC']],
|
||||||
|
['with' => ['operator', 'country']],
|
||||||
|
['paginate' => 300],
|
||||||
|
],
|
||||||
|
'page' => $page
|
||||||
|
];
|
||||||
|
|
||||||
|
$query = http_build_query($params);
|
||||||
|
|
||||||
|
$this->ch = curl_init($this->inserve_url . 'companies?' . $query);
|
||||||
|
|
||||||
|
curl_setopt_array($this->ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
"X-Api-Key: $this->inserve_token",
|
||||||
|
"Accept: application/json"
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->execCurl();
|
||||||
|
|
||||||
|
return json_decode($this->response, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function syncCompaniesFromSentri()
|
||||||
|
{
|
||||||
|
# First retrieve all the active companies to sync to the Inserver cloud distributor
|
||||||
|
$companies = [];
|
||||||
|
|
||||||
|
$sql = "SELECT company_source_id FROM companies WHERE company_state = 'active'";
|
||||||
|
$stmt = $this->conn->query($sql);
|
||||||
|
while ($row = $stmt->fetch_assoc()) {
|
||||||
|
$id = (int)$row['company_source_id'];
|
||||||
|
$companies[] = [
|
||||||
|
'cloud_distribution_id' => (string)$id,
|
||||||
|
'company_id' => $id
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = $this->inserve_url . 'cloud-distributors/digistate-servers/companies';
|
||||||
|
|
||||||
|
$this->ch = curl_init($url);
|
||||||
|
|
||||||
|
curl_setopt_array($this->ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_POST => true,
|
||||||
|
CURLOPT_POSTFIELDS => json_encode($companies),
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
"X-Api-Key: $this->inserve_token",
|
||||||
|
"Accept: application/json",
|
||||||
|
"Content-Type: application/json"
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->execCurl();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCloudSubscriptions()
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->ch = curl_init($this->inserve_url . 'cloud-distribution-subscriptions/');
|
||||||
|
|
||||||
|
curl_setopt_array($this->ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
"X-Api-Key: $this->inserve_token",
|
||||||
|
"Accept: application/json"
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->execCurl();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSubscription($subscriptionId = false, $payload = false)
|
||||||
|
{
|
||||||
|
$url = $this->inserve_url . 'cloud-distribution-subscriptions/' . $subscriptionId;
|
||||||
|
|
||||||
|
$this->ch = curl_init($url);
|
||||||
|
|
||||||
|
curl_setopt_array($this->ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_CUSTOMREQUEST => 'PUT',
|
||||||
|
CURLOPT_POSTFIELDS => json_encode($payload),
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
"X-Api-Key: $this->inserve_token",
|
||||||
|
"Accept: application/json",
|
||||||
|
"Content-Type: application/json"
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->execCurl();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getAllTypes($type)
|
||||||
|
{
|
||||||
|
$allowedColumns = [
|
||||||
|
'server_licenses',
|
||||||
|
'server_backup'
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!in_array($type, $allowedColumns, true)) {
|
||||||
|
throw new Exception('Invalid column name');
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "SELECT `$type` FROM servers";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
$servers = [];
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
array_push($servers, $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
$allTypes = [];
|
||||||
|
foreach ($servers as $server) {
|
||||||
|
if (!empty($server[$type])) {
|
||||||
|
$types = json_decode($server[$type], true);
|
||||||
|
if (is_array($types)) {
|
||||||
|
foreach ($types as $item) {
|
||||||
|
foreach ($item as $key => $value) {
|
||||||
|
$allTypes[$key . '.' . $value] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $allTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calculateTotalDiskUsage($diskJson)
|
||||||
|
{
|
||||||
|
$disks = json_decode($diskJson, true);
|
||||||
|
$server_disks_count = 0;
|
||||||
|
if (is_array($disks)) {
|
||||||
|
foreach ($disks as $disk) {
|
||||||
|
$server_disks_count += $disk['disk_space'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_array($disks) && count($disks) > 0) {
|
||||||
|
$sizes = array_column($disks, 'disk_space');
|
||||||
|
$server_disks_count = array_sum($sizes);
|
||||||
|
}
|
||||||
|
return $server_disks_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildCountObject(string $serverUuid, string $key): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'countSentri' => 0,
|
||||||
|
'countInserve' => 0,
|
||||||
|
'sentriCompanyId' => 0,
|
||||||
|
'SentriStatus' => 0,
|
||||||
|
'subscriptionInserveExists' => false,
|
||||||
|
'subscriptionInserveId' => false,
|
||||||
|
'subscriptionInserveCompanyId' => false,
|
||||||
|
'subscriptionInserveName' => false,
|
||||||
|
'subscriptionInserveStatus' => 0,
|
||||||
|
'md5' => md5($serverUuid . ':' . $key),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function transformTypes(array $types, string $serverUuid): array
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($types as $key => $value) {
|
||||||
|
$result[$key] = $this->buildCountObject($serverUuid, $key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildCountArray($serverUuid)
|
||||||
|
{
|
||||||
|
$allBackupTypes = $this->getAllTypes('server_backup');
|
||||||
|
$allLicenseTypes = $this->getAllTypes('server_licenses');
|
||||||
|
|
||||||
|
$backupCounts = $this->transformTypes($allBackupTypes, $serverUuid);
|
||||||
|
$licenseCounts = $this->transformTypes($allLicenseTypes, $serverUuid);
|
||||||
|
|
||||||
|
return array_merge(
|
||||||
|
[
|
||||||
|
"server_CPU_count" => $this->buildCountObject($serverUuid, 'server_cpu_count'),
|
||||||
|
"server_Memory_count" => $this->buildCountObject($serverUuid, 'server_memory_count'),
|
||||||
|
"server_Disk_space_count" => $this->buildCountObject($serverUuid, 'server_disks_count'),
|
||||||
|
],
|
||||||
|
$licenseCounts,
|
||||||
|
$backupCounts
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function syncServerLicencesToInserve()
|
||||||
|
{
|
||||||
|
# Get all the linked companies
|
||||||
|
$this->getLinkedCompanies();
|
||||||
|
$allCompanies = json_decode($this->response, true);
|
||||||
|
$allCompaniesIds = array_column($allCompanies['matched'], 'id', 'company_id');
|
||||||
|
|
||||||
|
# first get the current subscriptions
|
||||||
|
$this->getCloudSubscriptions();
|
||||||
|
$allInserveSubscriptions = json_decode($this->response, true);
|
||||||
|
|
||||||
|
# Filter out all the none Sentri posted subscriptions based on the name for performance
|
||||||
|
$allInserveSubscriptions = array_filter($allInserveSubscriptions, function ($subscription) {
|
||||||
|
return isset($subscription['cloud_subscription_id']) && $subscription['cloud_subscription_id'] === 'sentri-servers';
|
||||||
|
});
|
||||||
|
|
||||||
|
# Build lookup of existing Inserve subscriptions by cloud_distribution_id
|
||||||
|
# this will be used later to lookup
|
||||||
|
$inserveLookup = [];
|
||||||
|
foreach ($allInserveSubscriptions as $subscription) {
|
||||||
|
if (!empty($subscription['cloud_distribution_id'])) {
|
||||||
|
$inserveLookup[$subscription['cloud_distribution_id']] = [
|
||||||
|
'id' => (int)$subscription['id'],
|
||||||
|
'quantity' => (int)$subscription['quantity'],
|
||||||
|
'status' => (int)$subscription['status'],
|
||||||
|
'cloud_distribution_company_id' => (int)$subscription['cloud_distribution_company_id'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# get all the servers from Sentri
|
||||||
|
$sql = "SELECT * FROM servers INNER JOIN companies ON servers.company_uuid = companies.company_uuid WHERE company_state = 'active' AND server_state != 'new' AND server_state != 'disabled' ";
|
||||||
|
$stmt = $this->conn->query($sql);
|
||||||
|
|
||||||
|
while ($row = $stmt->fetch_assoc()) {
|
||||||
|
# Create a count of all the Subscriptions possible with every count on 0
|
||||||
|
$subscriptionCounts = $this->buildCountArray($row['server_uuid']);
|
||||||
|
$totalDiskSpace = $this->calculateTotalDiskUsage($row['server_disks']);
|
||||||
|
|
||||||
|
# Inserve status codes are:
|
||||||
|
# 0 = active, 1 = cancelled, 2 = pending, 3 = trial, 4 = on hold, 5 = removed
|
||||||
|
$statusMap = [
|
||||||
|
'active' => 0,
|
||||||
|
'trial' => 3,
|
||||||
|
'deleted' => 5,
|
||||||
|
];
|
||||||
|
|
||||||
|
// if no states matched there is something terrifying wrong, call the ambulance!
|
||||||
|
if (!isset($statusMap[$row['server_state']])) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$sentriStatus = $statusMap[$row['server_state']];
|
||||||
|
|
||||||
|
# Set all the server resource counts from Sentri into the $subscriptionCounts
|
||||||
|
$subscriptionCounts['server_CPU_count']['countSentri'] = $row['server_cpu'];
|
||||||
|
$subscriptionCounts['server_Memory_count']['countSentri'] = (int)ceil($row['server_memory'] / 1024);
|
||||||
|
$subscriptionCounts['server_Disk_space_count']['countSentri'] = $totalDiskSpace;
|
||||||
|
|
||||||
|
$licenses = json_decode($row['server_licenses'], true);
|
||||||
|
foreach ($licenses as $license) {
|
||||||
|
foreach ($license as $key => $LicenseType) {
|
||||||
|
$subscriptionCounts[$key . '.' . $LicenseType]['countSentri']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$backups = json_decode($row['server_backup'], true);
|
||||||
|
foreach ($backups as $backup) {
|
||||||
|
foreach ($backup as $key => $BackupType) {
|
||||||
|
$subscriptionCounts[$key . '.' . $BackupType]['countSentri'] = $totalDiskSpace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Mark subscriptions that already exist in Inserve
|
||||||
|
foreach ($subscriptionCounts as $key => &$item) {
|
||||||
|
if (!is_array($item) || !isset($item['md5'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$md5 = (string)$item['md5'];
|
||||||
|
|
||||||
|
if (isset($inserveLookup[$md5])) { # Subscription already exists in Inserve
|
||||||
|
$item['SentriStatus'] = $sentriStatus;
|
||||||
|
$item['sentriCompanyId'] = (int)$allCompaniesIds[$row['company_source_id']] ?? 0;
|
||||||
|
$item['subscriptionInserveExists'] = true;
|
||||||
|
$item['subscriptionInserveId'] = $inserveLookup[$item['md5']]['id'];
|
||||||
|
$item['countInserve'] = $inserveLookup[$item['md5']]['quantity'];
|
||||||
|
$item['subscriptionInserveCompanyId'] = $inserveLookup[$item['md5']]['cloud_distribution_company_id'];
|
||||||
|
$item['subscriptionInserveStatus'] = $inserveLookup[$item['md5']]['status'];
|
||||||
|
} else { # Subscription does not exists in Inserve
|
||||||
|
$item['sentriCompanyId'] = (int)$allCompaniesIds[$row['company_source_id']] ?? 0;
|
||||||
|
$item['subscriptionInserveExists'] = false;
|
||||||
|
$item['subscriptionInserveId'] = false;
|
||||||
|
$item['countInserve'] = 0;
|
||||||
|
$item['subscriptionInserveCompanyId'] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($item);
|
||||||
|
|
||||||
|
// Make the subscriptions names look nice and dandy.
|
||||||
|
foreach ($subscriptionCounts as $key => &$item) {
|
||||||
|
// Set server name
|
||||||
|
$serverName = $row['server_hostname'] ?? $row['server_vm_host_name'] ?? 'Unknown';
|
||||||
|
|
||||||
|
// remove server_ prefix and _count suffix
|
||||||
|
$namePart = $key;
|
||||||
|
if (str_starts_with($key, 'server_') && str_ends_with($key, '_count')) {
|
||||||
|
$namePart = substr($key, 7, -6);
|
||||||
|
$namePart = ucfirst($namePart);
|
||||||
|
} // Handle keys with "."
|
||||||
|
elseif (strpos($key, '.') !== false) {
|
||||||
|
[$first, $second] = explode('.', $key, 2);
|
||||||
|
if ($first === $second || strtolower($second) === 'yes') {
|
||||||
|
$namePart = ucfirst($first);
|
||||||
|
} else {
|
||||||
|
$namePart = ucfirst($first) . ' - ' . $second;
|
||||||
|
}
|
||||||
|
} //Handle keys without . but with a space (expmale directadmin.Standard Discounted)
|
||||||
|
elseif (strpos($key, ' ') !== false) {
|
||||||
|
// explode on first .
|
||||||
|
$parts = explode('.', $key, 2);
|
||||||
|
if (count($parts) === 2) {
|
||||||
|
$namePart = ucfirst($parts[0]) . ' - ' . $parts[1];
|
||||||
|
} else {
|
||||||
|
// Cap first word before first space
|
||||||
|
$spacePos = strpos($key, ' ');
|
||||||
|
$first = ucfirst(substr($key, 0, $spacePos));
|
||||||
|
$rest = substr($key, $spacePos + 1);
|
||||||
|
$namePart = $first . ' - ' . $rest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$item['subscriptionInserveName'] = $serverName . ' - ' . $namePart;
|
||||||
|
}
|
||||||
|
unset($item);
|
||||||
|
|
||||||
|
foreach ($subscriptionCounts as $key => $item) {
|
||||||
|
// if subscriptionInserveExists but the countInserve is null skip creation
|
||||||
|
if ($item['subscriptionInserveExists'] === false && (int)$item['countSentri'] === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if subscriptionInserveExists is false create a new subscription
|
||||||
|
if ($item['subscriptionInserveExists'] === false) {
|
||||||
|
$payload = [
|
||||||
|
"cloud_distribution_id" => $item['md5'], #md5 hash based on the server_uuid from sentri and the subscription name (eg. server_cpu_count)
|
||||||
|
"cloud_subscription_id" => "sentri-servers", # Mark all the sentri-servers subscriptions so we can filter the subscriptions better
|
||||||
|
"name" => $item['subscriptionInserveName'],
|
||||||
|
"quantity" => $item['countSentri'],
|
||||||
|
"cloud_distribution_company_id" => $item['sentriCompanyId'], # this is generated by inserve (306 = digistate)
|
||||||
|
"status" => $item['SentriStatus'],
|
||||||
|
"period_type" => 0, # 0 = monthly, 1 = anual, 2 = one time cost
|
||||||
|
"start_date" => date('Y-m-d')
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->createSubscription($payload);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the subscription if the countInserve and countSentri dont match
|
||||||
|
// Or when sentriCompanyId and subscriptionInserveCompanyId dont match
|
||||||
|
if ((
|
||||||
|
(int)$item['countInserve'] !== (int)$item['countSentri'] ||
|
||||||
|
(int)$item['sentriCompanyId'] !== (int)$item['subscriptionInserveCompanyId'] ||
|
||||||
|
(int)$item['SentriStatus'] !== (int)$item['subscriptionInserveStatus']
|
||||||
|
)
|
||||||
|
&& $item['subscriptionInserveExists'] !== false
|
||||||
|
) {
|
||||||
|
|
||||||
|
|
||||||
|
$payload = [
|
||||||
|
"quantity" => (int)$item['countSentri'],
|
||||||
|
"cloud_distribution_company_id" => (int)$item['sentriCompanyId'],
|
||||||
|
"name" => $item['subscriptionInserveName'],
|
||||||
|
"status" => $item['SentriStatus'],
|
||||||
|
"quantity" => $item['countSentri']
|
||||||
|
];
|
||||||
|
$this->updateSubscription($item['subscriptionInserveId'], $payload);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createSubscription($payload)
|
||||||
|
{
|
||||||
|
$url = $this->inserve_url . 'cloud-distribution-subscriptions';
|
||||||
|
$this->ch = curl_init($url);
|
||||||
|
|
||||||
|
# I need to make this pay load:
|
||||||
|
curl_setopt_array($this->ch, [
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_POST => true,
|
||||||
|
CURLOPT_POSTFIELDS => json_encode($payload),
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
"X-Api-Key: $this->inserve_token",
|
||||||
|
"Accept: application/json",
|
||||||
|
"Content-Type: application/json"
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->execCurl();
|
||||||
|
}
|
||||||
|
}
|
||||||
30
pub/api/classes/API_mailsettings.php
Normal file
30
pub/api/classes/API_mailsettings.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_mailsettings extends API
|
||||||
|
{
|
||||||
|
public function updateMailSettings($updatePassword)
|
||||||
|
{
|
||||||
|
if ($updatePassword) {
|
||||||
|
$query = "UPDATE vc_portal_settings SET mail_from_name = ?, mail_from_address = ?, mail_smtp_host = ?, mail_smtp_secure = ?, mail_smtp_port = ?, mail_smtp_auth = ?, mail_smtp_user = ?, mail_smtp_pass = ? WHERE portal_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('ssssiisss', $this->data['mail_from_name'], $this->data['mail_from_address'], $this->data['mail_smtp_host'], $this->data['mail_smtp_secure'], $this->data['mail_smtp_port'], $this->data['mail_smtp_auth'], $this->data['mail_smtp_user'], $this->data['mail_smtp_pass'], $this->data['portal_uuid']);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$query = "UPDATE vc_portal_settings SET mail_from_name = ?, mail_from_address = ?, mail_smtp_host = ?, mail_smtp_secure = ?, mail_smtp_port = ?, mail_smtp_auth = ?, mail_smtp_user = ? WHERE portal_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('ssssiiss', $this->data['mail_from_name'], $this->data['mail_from_address'], $this->data['mail_smtp_host'], $this->data['mail_smtp_secure'], $this->data['mail_smtp_port'], $this->data['mail_smtp_auth'], $this->data['mail_smtp_user'], $this->data['portal_uuid']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'mail settings updated successfully.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
40
pub/api/classes/API_mfa.php
Normal file
40
pub/api/classes/API_mfa.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_mfa extends API
|
||||||
|
{
|
||||||
|
public function disableMFA()
|
||||||
|
{
|
||||||
|
# Users cannot, by default disable MFA of other users
|
||||||
|
if ($this->getUserUuid() != $this->data['user_uuid']) {
|
||||||
|
$this->checkPermissions('admin-access-admins-mfa', 'RW');
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "UPDATE vc_users SET user_two_factor_enabled = 0, user_two_factor_secret = NULL WHERE user_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("s", $this->data['user_uuid']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'mfa is disabled']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enableMFA()
|
||||||
|
{
|
||||||
|
# Users cannot, create MFA of other users
|
||||||
|
if ($this->getUserUuid() != $this->data['user_uuid']) {
|
||||||
|
$this->apiOutput(401, ['error' => 'you are not allowed to enable mfa for others']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "UPDATE vc_users SET user_two_factor_enabled = 1, user_two_factor_secret = ? WHERE user_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("ss", $this->data['user_two_factor_secret'], $this->data['user_uuid']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'mfa is enabled']);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
pub/api/classes/API_office_stompjes.php
Normal file
32
pub/api/classes/API_office_stompjes.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_office_stompjes extends API
|
||||||
|
{
|
||||||
|
public function addStomp()
|
||||||
|
{
|
||||||
|
$query = "INSERT INTO office_stompjes (stomp_uuid, user_uuid, stomp_timestamp) VALUES (UUID(), ?, ?)";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('si', $this->data['user_uuid'], time());
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'Stomp added.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteStomp()
|
||||||
|
{
|
||||||
|
$query = "DELETE FROM office_stompjes WHERE stomp_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('s', $this->data['stomp_uuid']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'Stomp removed.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
123
pub/api/classes/API_permissions.php
Normal file
123
pub/api/classes/API_permissions.php
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_permissions extends API
|
||||||
|
{
|
||||||
|
public function getPermission($returnBoolean = false)
|
||||||
|
{
|
||||||
|
list($query, $types, $params) = $this->buildDynamicQuery('vc_permissions');
|
||||||
|
|
||||||
|
$items = $this->generalGetFunction($query, $types, $params, $returnBoolean, 'Permission');
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deletePermission()
|
||||||
|
{
|
||||||
|
$query = "DELETE FROM vc_permissions WHERE permission_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('s', $this->data['permission_uuid']);
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'Permission deleted successfully.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createPermission()
|
||||||
|
{
|
||||||
|
# Check if permission slugify already exists
|
||||||
|
$result = $this->getPermissionSlugify();
|
||||||
|
if ($result->num_rows > 0) {
|
||||||
|
$this->apiOutput(409, ['error' => 'Permission slugify already exists'], 'item_already_exists!');
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "INSERT INTO vc_permissions (permission_uuid, permission_name, permission_slugify, permission_description, permission_create_timestamp, module_uuid) VALUES (UUID(), ?, ?, ?, ?, ?)";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('sssis', $this->data['permission_name'], $this->data['permission_slugify'], $this->data['permission_description'], time(), $this->data['module_uuid']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
$result = $this->getPermissionSlugify();
|
||||||
|
if ($result->num_rows === 0) {
|
||||||
|
$this->apiOutput(500, ['error' => 'Something went wrong creating the platform on the server.'], 'error_contact_support');
|
||||||
|
}
|
||||||
|
|
||||||
|
$permission_data = $result->fetch_assoc();
|
||||||
|
|
||||||
|
# Get all the groups so we can create the permissions for the group
|
||||||
|
$user_groups = array();
|
||||||
|
$sql = "SELECT * FROM vc_user_groups";
|
||||||
|
$stmt = $this->conn->query($sql);
|
||||||
|
while ($user_group = $stmt->fetch_assoc()) {
|
||||||
|
array_push($user_groups, $user_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Update all the groups with the newly added permission
|
||||||
|
foreach ($user_groups as $user_group) {
|
||||||
|
$query = "INSERT INTO vc_user_group_permissions_portal (permission_uuid, user_group_uuid, permission_value) VALUES (?, ?, ?)";
|
||||||
|
$permission_value = 'NA';
|
||||||
|
if ($user_group['user_group_name'] == 'superuser') {
|
||||||
|
$permission_value = 'RW';
|
||||||
|
}
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("sss", $permission_data['permission_uuid'], $user_group['user_group_uuid'], $permission_value);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => $permission_data], 'item_added');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPermissionSlugify()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM vc_permissions WHERE permission_slugify = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("s", $this->data['permission_slugify']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
return $stmt->get_result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatePermission()
|
||||||
|
{
|
||||||
|
$query = "UPDATE vc_permissions SET permission_name = ?, permission_description = ?, permission_modified_timestamp = ?, module_uuid = ? WHERE permission_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('ssiss', $this->data['permission_name'], $this->data['permission_description'], time(), $this->data['module_uuid'], $this->data['permission_uuid']);
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'Permission updated successfully.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAccessRights()
|
||||||
|
{
|
||||||
|
$query = "UPDATE vc_user_group_permissions_portal SET permission_value = ? WHERE permission_uuid = ? AND user_group_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('sss', $this->data['permission_value'], $this->data['permission_uuid'], $this->data['user_group_uuid']);
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'Access rights changed successfully.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPermissionRights()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM vc_permissions
|
||||||
|
INNER JOIN vc_user_group_permissions_portal ON vc_permissions.permission_uuid = vc_user_group_permissions_portal.permission_uuid
|
||||||
|
INNER JOIN vc_user_groups ON vc_user_group_permissions_portal.user_group_uuid = vc_user_groups.user_group_uuid
|
||||||
|
WHERE vc_permissions.permission_uuid = ? ORDER BY vc_user_groups.user_group_weight ASC";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('s', $this->data['permission_uuid']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
$access_rights = [];
|
||||||
|
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$access_rights[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $access_rights;
|
||||||
|
}
|
||||||
|
}
|
||||||
72
pub/api/classes/API_platforms.php
Normal file
72
pub/api/classes/API_platforms.php
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_platforms extends API
|
||||||
|
{
|
||||||
|
public function getPlatforms($returnBoolean = false)
|
||||||
|
{
|
||||||
|
list($query, $types, $params) = $this->buildDynamicQuery('vc_platforms');
|
||||||
|
|
||||||
|
$items = $this->generalGetFunction($query, $types, $params, $returnBoolean, 'Platform');
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function createPlatforms()
|
||||||
|
{
|
||||||
|
if (isset($this->data['platform_image'])) {
|
||||||
|
$query = "INSERT INTO vc_platforms (platform_uuid, platform_name, platform_slugify, platform_description, platform_enabled, platform_image, platform_create_timestamp) VALUES (UUID(), ?, ?, ?, ?, ?, ?)";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('sssssi', $this->data['platform_name'], $this->data['platform_slugify'], $this->data['platform_description'], $this->data['platform_enabled'], $this->data['platform_image'], time());
|
||||||
|
} else {
|
||||||
|
$query = "INSERT INTO vc_platforms (platform_uuid, platform_name, platform_slugify, platform_description, platform_enabled, platform_create_timestamp) VALUES (UUID(), ?, ?, ?, ?, ?)";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('ssssi', $this->data['platform_name'], $this->data['platform_slugify'], $this->data['platform_description'], $this->data['platform_enabled'], time());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
$result = $this->getPlatformSlugify();
|
||||||
|
if ($result->num_rows === 0) {
|
||||||
|
$this->apiOutput(500, ['error' => 'Something went wrong creating the platform on the server.'], 'error_contact_support');
|
||||||
|
}
|
||||||
|
|
||||||
|
$platform_data = $result->fetch_assoc();
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => $platform_data], 'item_added');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlatformSlugify()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM vc_platforms WHERE platform_slugify = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("s", $this->data['platform_slugify']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
return $stmt->get_result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function editPlatforms()
|
||||||
|
{
|
||||||
|
if (isset($this->data['platform_image'])) {
|
||||||
|
$query = "UPDATE vc_platforms SET platform_name = ?, platform_description = ?, platform_enabled = ?, platform_image = ?, platform_modified_timestamp = ? WHERE platform_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("ssisis", $this->data['platform_name'], $this->data['platform_description'], $this->data['platform_enabled'], $this->data['platform_image'], time(), $this->data['platform_uuid']);
|
||||||
|
} else {
|
||||||
|
$query = "UPDATE vc_platforms SET platform_name = ?, platform_description = ?, platform_enabled = ?, platform_modified_timestamp = ? WHERE platform_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("ssiis", $this->data['platform_name'], $this->data['platform_description'], $this->data['platform_enabled'], time(), $this->data['platform_uuid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'Platform updated successfully.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
21
pub/api/classes/API_portalsettings.php
Normal file
21
pub/api/classes/API_portalsettings.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_portalsettings extends API
|
||||||
|
{
|
||||||
|
public function updatePortalSettings()
|
||||||
|
{
|
||||||
|
$query = "UPDATE vc_portal_settings SET portal_name = ?, portal_provider_name = ?, admin_auth_methods = ? WHERE portal_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("ssss", $this->data['portal_name'], $this->data['portal_provider_name'], $this->data['admin_auth_methods'], $this->data['portal_uuid']);
|
||||||
|
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'portal settings updated successfully.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
pub/api/classes/API_resetpassword.php
Normal file
26
pub/api/classes/API_resetpassword.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_resetpassword extends API
|
||||||
|
{
|
||||||
|
public function resetPassword()
|
||||||
|
{
|
||||||
|
|
||||||
|
$query = "UPDATE vc_users SET user_password = ?, user_password_reset_token = ?, user_password_reset_expires = ? WHERE user_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("ssis",
|
||||||
|
$this->data['user_password'],
|
||||||
|
$this->data['user_password_reset_token'],
|
||||||
|
$this->data['user_password_reset_expires'],
|
||||||
|
$this->data['user_uuid']
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
269
pub/api/classes/API_servers.php
Normal file
269
pub/api/classes/API_servers.php
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use JsonException;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_servers extends API
|
||||||
|
{
|
||||||
|
public function validateDiskData($disks)
|
||||||
|
{
|
||||||
|
foreach ($disks as $index => $disk) {
|
||||||
|
|
||||||
|
// Ensure $disk is an array
|
||||||
|
if (!is_array($disk)) {
|
||||||
|
$this->apiOutput(400, ['error' => "Disk entry is not an array"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$requiredFields = ['disk_name', 'disk_space', 'disk_used', 'disk_location'];
|
||||||
|
|
||||||
|
foreach ($requiredFields as $field) {
|
||||||
|
if (!array_key_exists($field, $disk)) {
|
||||||
|
$this->apiOutput(400, ['error' => "Missing required field '$field' in disk information"]);
|
||||||
|
}
|
||||||
|
switch ($field) {
|
||||||
|
case 'disk_used':
|
||||||
|
case 'disk_space':
|
||||||
|
$disks[$index][$field] = $this->validateSingleData($disk[$field], ['type' => 'float']);
|
||||||
|
break;
|
||||||
|
case 'disk_location':
|
||||||
|
case 'disk_name':
|
||||||
|
$disks[$index][$field] = $this->validateSingleData($disk[$field], ['type' => 'string']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return json_encode($disks, JSON_THROW_ON_ERROR);
|
||||||
|
} catch (JsonException $e) {
|
||||||
|
$this->apiOutput(400, ['error' => "Failed to encode disk data to JSON: " . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function updateServer()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (isset($this->data['company_uuid'])) {
|
||||||
|
if (strlen($this->data['company_uuid']) == 0) {
|
||||||
|
$this->data['company_uuid'] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields = [
|
||||||
|
'company_uuid',
|
||||||
|
'server_vm_id',
|
||||||
|
'server_vm_host_id',
|
||||||
|
'server_vm_host_name',
|
||||||
|
'server_power_state',
|
||||||
|
'server_state',
|
||||||
|
'server_hostname',
|
||||||
|
'server_os',
|
||||||
|
'server_cpu',
|
||||||
|
'server_memory',
|
||||||
|
'server_memory_demand',
|
||||||
|
'server_disks',
|
||||||
|
'server_ipv4',
|
||||||
|
'server_ipv6',
|
||||||
|
'server_vm_generation',
|
||||||
|
'server_vm_snapshot',
|
||||||
|
'server_licenses',
|
||||||
|
'server_backup',
|
||||||
|
'server_description'
|
||||||
|
];
|
||||||
|
|
||||||
|
$insertFields = ['server_uuid'];
|
||||||
|
$insertValues = ['UUID()'];
|
||||||
|
$bindParams = [];
|
||||||
|
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
if (array_key_exists($field, $this->data)) {
|
||||||
|
$insertFields[] = $field;
|
||||||
|
$insertValues[] = ":$field";
|
||||||
|
$bindParams[":$field"] = $this->data[$field]; // can be NULL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Always include server_create_timestamp and server_modified_timestamp
|
||||||
|
$insertFields[] = 'server_create_timestamp';
|
||||||
|
$insertValues[] = ':server_create_timestamp';
|
||||||
|
$bindParams[':server_create_timestamp'] = time();
|
||||||
|
|
||||||
|
$insertFields[] = 'server_modified_timestamp';
|
||||||
|
$insertValues[] = ':server_modified_timestamp';
|
||||||
|
$bindParams[':server_modified_timestamp'] = time();
|
||||||
|
|
||||||
|
$query = "INSERT INTO servers (" . implode(',', $insertFields) . ")
|
||||||
|
VALUES (" . implode(',', $insertValues) . ")
|
||||||
|
ON DUPLICATE KEY UPDATE ";
|
||||||
|
|
||||||
|
# Build the ON DUPLICATE KEY UPDATE, only foor fields that exist
|
||||||
|
$updateParts = [];
|
||||||
|
foreach ($insertFields as $field) {
|
||||||
|
if (!in_array($field, ['server_create_timestamp', 'server_uuid'])) {
|
||||||
|
$updateParts[] = "$field = VALUES($field)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$query .= implode(", ", $updateParts);
|
||||||
|
|
||||||
|
$stmt = $GLOBALS['pdo']->prepare($query);
|
||||||
|
|
||||||
|
if (!$stmt->execute($bindParams)) {
|
||||||
|
$this->apiOutput(400, ['error' => "Failed to insert server into database"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validateLicenseData($server_vm_id, $server_licenses)
|
||||||
|
{
|
||||||
|
$server_vm_id = $this->validateSingleData($server_vm_id, ['type' => 'string']);
|
||||||
|
$server_licenses_posted = $this->validateSingleData($server_licenses, ['type' => 'array']);
|
||||||
|
|
||||||
|
$query = "SELECT server_licenses FROM servers WHERE server_vm_id = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("s", $server_vm_id);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
$server_licenses_db = $result->fetch_assoc();
|
||||||
|
|
||||||
|
$server_licenses_db = $server_licenses_db['server_licenses'] ?? null;
|
||||||
|
$server_licenses_db_new = [];
|
||||||
|
if (!empty($server_licenses_db)) {
|
||||||
|
$decoded = json_decode($server_licenses_db, true);
|
||||||
|
if (is_array($decoded)) {
|
||||||
|
foreach ($decoded as $item) {
|
||||||
|
foreach ($item as $key => $value) {
|
||||||
|
$server_licenses_db_new[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($server_licenses_posted as $item) {
|
||||||
|
foreach ($item as $rawKey => $value) {
|
||||||
|
|
||||||
|
$prefix = substr($rawKey, 0, 1);
|
||||||
|
$license = substr($rawKey, 1);
|
||||||
|
|
||||||
|
if ($prefix === '+') {
|
||||||
|
$server_licenses_db_new[$license] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prefix === '-') {
|
||||||
|
unset($server_licenses_db_new[$license]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$server_licenses_db_new_final = [];
|
||||||
|
foreach ($server_licenses_db_new as $key => $value) {
|
||||||
|
$server_licenses_db_new_final[] = [$key => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
return empty($server_licenses_db_new_final) ? '[]' : json_encode($server_licenses_db_new_final);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validateBackupData($server_vm_id, $server_backup)
|
||||||
|
{
|
||||||
|
$server_vm_id = $this->validateSingleData($server_vm_id, ['type' => 'string']);
|
||||||
|
$server_backup_posted = $this->validateSingleData($server_backup, ['type' => 'array']);
|
||||||
|
|
||||||
|
$query = "SELECT server_backup FROM servers WHERE server_vm_id = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("s", $server_vm_id);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
$server_backup_db = $result->fetch_assoc();
|
||||||
|
|
||||||
|
$server_backup_db = $server_backup_db['server_backup'] ?? null;
|
||||||
|
$server_backup_db_new = [];
|
||||||
|
if (!empty($server_backup_db)) {
|
||||||
|
$decoded = json_decode($server_backup_db, true);
|
||||||
|
if (is_array($decoded)) {
|
||||||
|
foreach ($decoded as $item) {
|
||||||
|
foreach ($item as $key => $value) {
|
||||||
|
$server_backup_db_new[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($server_backup_posted as $item) {
|
||||||
|
foreach ($item as $rawKey => $value) {
|
||||||
|
|
||||||
|
$prefix = substr($rawKey, 0, 1);
|
||||||
|
$backup = substr($rawKey, 1);
|
||||||
|
|
||||||
|
if ($prefix === '+') {
|
||||||
|
$server_backup_db_new[$backup] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prefix === '-') {
|
||||||
|
unset($server_backup_db_new[$backup]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$server_backup_db_new_final = [];
|
||||||
|
foreach ($server_backup_db_new as $key => $value) {
|
||||||
|
$server_backup_db_new_final[] = [$key => $value];
|
||||||
|
}
|
||||||
|
|
||||||
|
return empty($server_backup_db_new_final) ? '[]' : json_encode($server_backup_db_new_final);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function processServerData($server, $requiredFields, $optionalFields)
|
||||||
|
{
|
||||||
|
// since the disk data is sent as an array we need to check it seperatly from the other data validations
|
||||||
|
|
||||||
|
if (!empty($server['server_disks']) && is_array($server['server_disks'])) {
|
||||||
|
$server['server_disks'] = $this->validateDiskData($server['server_disks']);
|
||||||
|
} else {
|
||||||
|
unset($server['server_disks']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($server['server_licenses']) && is_array($server['server_licenses'])) {
|
||||||
|
$server['server_licenses'] = $this->validateLicenseData($server['server_vm_id'], $server['server_licenses']);
|
||||||
|
} else {
|
||||||
|
unset($server['server_licenses']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($server['server_backup']) && is_array($server['server_backup'])) {
|
||||||
|
$server['server_backup'] = $this->validateBackupData($server['server_vm_id'], $server['server_backup']);
|
||||||
|
} else {
|
||||||
|
unset($server['server_backup']);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (['server_ipv4', 'server_ipv6'] as $key) {
|
||||||
|
if (!empty($server[$key]) && is_array($server[$key])) {
|
||||||
|
$server[$key] = json_encode($server[$key]);
|
||||||
|
} else {
|
||||||
|
unset($server[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->postedData = $server;
|
||||||
|
|
||||||
|
$this->validateData($requiredFields, $optionalFields);
|
||||||
|
|
||||||
|
$this->updateServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteServer()
|
||||||
|
{
|
||||||
|
$query = "DELETE FROM servers WHERE server_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('s', $this->data['server_uuid']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'Server removed']);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
pub/api/classes/API_system_modules.php
Normal file
34
pub/api/classes/API_system_modules.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_system_modules extends API
|
||||||
|
{
|
||||||
|
public function getModules($returnBoolean = false)
|
||||||
|
{
|
||||||
|
list($query, $types, $params) = $this->buildDynamicQuery('system_modules');
|
||||||
|
|
||||||
|
$items = $this->generalGetFunction($query, $types, $params, $returnBoolean, 'Permission');
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enableModule()
|
||||||
|
{
|
||||||
|
|
||||||
|
$module_uuid_enabled = ($this->data['module_enabled']) ? 0 : 1;
|
||||||
|
|
||||||
|
# Module 'system cannot be disabled'
|
||||||
|
$query = "UPDATE system_modules SET module_enabled = ? WHERE module_uuid = ? AND module_slugify != 'system'";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('is', $module_uuid_enabled, $this->data['module_uuid']);
|
||||||
|
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'Module ' . ($module_uuid_enabled ? 'enabled' : 'disabled') . ' successfully.']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
pub/api/classes/API_system_sources.php
Normal file
26
pub/api/classes/API_system_sources.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_system_sources extends API
|
||||||
|
{
|
||||||
|
public function inserveUpdate()
|
||||||
|
{
|
||||||
|
$query = "INSERT INTO system_sources (source_uuid, source_name, source_url, source_auth_username, source_auth_password, source_auth_token, source_create_timestamp, source_modified_timestamp)
|
||||||
|
VALUES (UUID(), ?, ?, '', '', ?, ?, NULL)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
source_url = VALUES(source_url),
|
||||||
|
source_auth_token = VALUES(source_auth_token),
|
||||||
|
source_modified_timestamp = VALUES(source_create_timestamp)";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('sssi', $this->data['source_name'], $this->data['source_url'], $this->data['source_auth_token'], time());
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'Information modified'], 'Information updated successfully.');
|
||||||
|
}
|
||||||
|
}
|
||||||
140
pub/api/classes/API_usergroups.php
Normal file
140
pub/api/classes/API_usergroups.php
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_usergroups extends API
|
||||||
|
{
|
||||||
|
public function getUsergroup($returnBoolean = false)
|
||||||
|
{
|
||||||
|
list($query, $types, $params) = $this->buildDynamicQuery('vc_user_groups');
|
||||||
|
|
||||||
|
$items = $this->generalGetFunction($query, $types, $params, $returnBoolean, 'User Group');
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createUsergroups()
|
||||||
|
{
|
||||||
|
# check if the user_group already exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'user_group_slugify', 1 => $this->data['user_group_slugify']]]];
|
||||||
|
|
||||||
|
if ($this->getUsergroup(true)) {
|
||||||
|
$this->apiOutput(409, ['error' => 'Usergroup already exists.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->data['user_group_weight'] = $this->get_next_available_user_group_weight($this->data['user_group_weight']);
|
||||||
|
|
||||||
|
if ($this->data['user_group_weight'] < $_SESSION['user']['user_group_weight']) {
|
||||||
|
$this->apiOutput(400, ['error' => 'You cannot make an group with an lower weight then yourself!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "INSERT INTO vc_user_groups (user_group_uuid, user_group_name, user_group_slugify, user_group_weight, user_group_type, user_group_create_timestamp) VALUES (UUID(), ?, ?, ?, ?, ?)";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("ssisi", $this->data['user_group_name'], $this->data['user_group_slugify'], $this->data['user_group_weight'], $this->data['user_group_type'], time());
|
||||||
|
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$user_group = $this->getUsergroup();
|
||||||
|
$user_group_uuid = $user_group[0]['user_group_uuid'];
|
||||||
|
|
||||||
|
|
||||||
|
# Get all the permission from the database and create the permission for the user group.
|
||||||
|
$stmt = $this->conn->query("SELECT permission_uuid FROM vc_permissions");
|
||||||
|
while ($row = $stmt->fetch_assoc()) {
|
||||||
|
$permission_uuids[] = $row['permission_uuid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$values = [];
|
||||||
|
foreach ($permission_uuids as $permission_uuid) {
|
||||||
|
$permission_uuid_safe = $GLOBALS['conn']->real_escape_string($permission_uuid);
|
||||||
|
$values[] = "('$permission_uuid_safe', '$user_group_uuid')";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($values)) {
|
||||||
|
$values_sql = implode(", ", $values);
|
||||||
|
|
||||||
|
$query = "INSERT INTO vc_user_group_permissions_portal (permission_uuid, user_group_uuid) VALUES $values_sql";
|
||||||
|
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'User group created successfully']);
|
||||||
|
} else {
|
||||||
|
$this->apiOutput(500, ['error' => 'Something went wrong creating the user-group.'], 'error_contact_support');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteUsergroup()
|
||||||
|
{
|
||||||
|
# check if the user group exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'user_group_uuid', 1 => $this->data['user_group_uuid']]]];
|
||||||
|
$user_group = $this->getUsergroup();
|
||||||
|
|
||||||
|
# superuser cannot be deleted
|
||||||
|
if ($user_group[0]['user_group_slufigy'] === 'superuser') {
|
||||||
|
$this->apiOutput(400, ['error' => 'superuser cannot be deleted.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user_group[0]['user_group_weight'] < $_SESSION['user']['user_group_weight']) {
|
||||||
|
$this->apiOutput(400, ['error' => 'groups with an lower weight cannot be deleted.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "DELETE FROM vc_user_groups WHERE user_group_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('s', $this->data['user_group_uuid']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'User group created deleted']);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_next_available_user_group_weight($weight)
|
||||||
|
{
|
||||||
|
# checks what the next avail weight is if the weight is taken by another item
|
||||||
|
$sql = "SELECT user_group_weight FROM vc_user_groups ORDER BY user_group_weight ASC";
|
||||||
|
$result = $this->conn->query($sql);
|
||||||
|
|
||||||
|
// Store all existing weights in an array
|
||||||
|
$existing_weights = [];
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$existing_weights[] = (int)$row['user_group_weight'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If weight already exists, find the next available integer
|
||||||
|
while (in_array($weight, $existing_weights)) {
|
||||||
|
$weight++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateUserGroup()
|
||||||
|
{
|
||||||
|
# check if the user group exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'user_group_uuid', 1 => $this->data['user_group_uuid']]]];
|
||||||
|
$user_group = $this->getUsergroup();
|
||||||
|
|
||||||
|
# superuser cannot be modified
|
||||||
|
if ($user_group[0]['user_group_slufigy'] === 'superuser') {
|
||||||
|
$this->apiOutput(500, ['error' => 'superuser cannot be modified']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user_group[0]['user_group_weight'] != $this->data['user_group_weight']) {
|
||||||
|
$this->data['user_group_weight'] = $this->get_next_available_user_group_weight($this->data['user_group_weight']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->data['user_group_weight'] < $_SESSION['user']['user_group_weight']) {
|
||||||
|
$this->apiOutput(400, ['error' => 'You cannot make an group with an lower weight then yourself!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "UPDATE vc_user_groups SET user_group_name = ?, user_group_weight = ?, user_group_modified_timestamp = ? WHERE user_group_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("siis", $this->data['user_group_name'], $this->data['user_group_weight'], time(), $this->data['user_group_uuid']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'User group created updated']);
|
||||||
|
}
|
||||||
|
}
|
||||||
151
pub/api/classes/API_users.php
Normal file
151
pub/api/classes/API_users.php
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use api\classes\API_usergroups;
|
||||||
|
use bin\php\Classes\mailBuilder;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/mailBuilder.php';
|
||||||
|
|
||||||
|
class API_users extends API
|
||||||
|
{
|
||||||
|
public function getUser($returnBoolean = false)
|
||||||
|
{
|
||||||
|
list($query, $types, $params) = $this->buildDynamicQuery('vc_users');
|
||||||
|
|
||||||
|
$items = $this->generalGetFunction($query, $types, $params, $returnBoolean, 'User');
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createUser()
|
||||||
|
{
|
||||||
|
# check if the user already exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'user_email', 1 => $this->data['user_email']]]];
|
||||||
|
|
||||||
|
if ($this->getUser(true)) {
|
||||||
|
$this->apiOutput(409, ['error' => 'user already exists.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($this->getUserGroupWeight() < $_SESSION['user']['user_group_weight']) {
|
||||||
|
$this->apiOutput(400, ['error' => 'You cannot make an user with an lower weight then yourself!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "INSERT INTO vc_users (
|
||||||
|
user_uuid, user_group_uuid, user_email, user_first_name, user_last_name, user_full_name,
|
||||||
|
user_phone_number, user_password, user_password_reset_token, user_password_reset_expires,
|
||||||
|
user_two_factor_enabled, user_two_factor_secret, user_status,
|
||||||
|
user_verified_email, user_verified_phone, user_create_timestamp, user_modified_timestamp,
|
||||||
|
user_last_login_timestamp, user_login_attempts, user_pref_language, user_stompable
|
||||||
|
) VALUES (
|
||||||
|
UUID(), ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, NULL, ?, 0, 0, ?, NULL, NULL, 0, ?, 0
|
||||||
|
)";
|
||||||
|
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
|
||||||
|
$stmt->bind_param("ssssssssisis",
|
||||||
|
$this->data['user_group_uuid'],
|
||||||
|
$this->data['user_email'],
|
||||||
|
$this->data['user_first_name'],
|
||||||
|
$this->data['user_last_name'],
|
||||||
|
$this->data['user_full_name'],
|
||||||
|
$this->data['user_phone_number'],
|
||||||
|
$this->data['user_password'],
|
||||||
|
$this->data['user_password_reset_token'],
|
||||||
|
$this->data['user_password_reset_expires'],
|
||||||
|
$this->data['user_status'],
|
||||||
|
time(),
|
||||||
|
$this->data['user_pref_language'],
|
||||||
|
);
|
||||||
|
|
||||||
|
# Sending an email to the user
|
||||||
|
$host = $_SERVER['HTTP_HOST'];
|
||||||
|
$verifyLink = "https://{$host}/login/verifyEmail.php?token={$this->data['user_password_reset_token']}";
|
||||||
|
|
||||||
|
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$mail = new mailBuilder();
|
||||||
|
$mail->subject = "Hello " . $this->data['user_first_name'] . ", your Sentri account is ready — set your password";
|
||||||
|
$mail->addAddress($this->data['user_email'], $this->data['user_first_name']);
|
||||||
|
$mail->mailText = '
|
||||||
|
Hello ' . $this->data['user_first_name'] . ',<br><br>
|
||||||
|
An account has been created for you in Sentri.<br>
|
||||||
|
To activate your account, please verify your email address and set your password by clicking the link below:<br>
|
||||||
|
<a href="' . $verifyLink . '" class="btn btn-primary">Activate My Account</a><br><br>
|
||||||
|
Or copy and paste the following link into your browser: <br>' . $verifyLink . '<br><br>
|
||||||
|
|
||||||
|
This link is valid for 24 hours.<br>
|
||||||
|
After that, you’ll need to request a new activation link.<br><br>
|
||||||
|
|
||||||
|
If you weren’t expecting this email or believe it was sent by mistake, you can safely ignore it.<br><br>
|
||||||
|
|
||||||
|
Best regards,<br><br>
|
||||||
|
The Sentri gnomes';
|
||||||
|
$mail->sendMail();
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'User created successfully. mail has been sent']);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getUserGroupWeight()
|
||||||
|
{
|
||||||
|
require_once 'API_usergroups.php';
|
||||||
|
|
||||||
|
$API_usergroups = new API_usergroups();
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'user_group_uuid', 1 => $this->data['user_group_uuid']]]];
|
||||||
|
|
||||||
|
return $API_usergroups->getUserGroup()[0]['user_group_weight'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateUser()
|
||||||
|
{
|
||||||
|
# check if the user exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'user_uuid', 1 => $this->data['user_uuid']]]];
|
||||||
|
$this->getUser();
|
||||||
|
|
||||||
|
if ($this->getUserGroupWeight() < $_SESSION['user']['user_group_weight']) {
|
||||||
|
$this->apiOutput(400, ['error' => 'You cannot edit a user with an lower weight then yourself!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "UPDATE vc_users SET user_group_uuid = ?, user_email = ?, user_first_name = ?, user_last_name = ?, user_full_name = ?, user_phone_number = ?, user_status = ?, user_pref_language = ?, user_modified_timestamp = ?, user_stompable = ? WHERE user_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('ssssssssiis', $this->data['user_group_uuid'], $this->data['user_email'], $this->data['user_first_name'], $this->data['user_last_name'], $this->data['user_full_name'], $this->data['user_phone_number'], $this->data['user_status'], $this->data['user_pref_language'], time(), $this->data['user_stompable'], $this->data['user_uuid']);
|
||||||
|
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'User successfully updated.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteUser()
|
||||||
|
{
|
||||||
|
# delete an user
|
||||||
|
|
||||||
|
# chect if the user exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'user_uuid', 1 => $this->data['user_uuid']]]];
|
||||||
|
$user_data = $this->getUser()[0];
|
||||||
|
|
||||||
|
|
||||||
|
$this->data['user_group_uuid'] = $user_data['user_group_uuid'];
|
||||||
|
|
||||||
|
# check group weigth
|
||||||
|
if ($this->getUserGroupWeight() < $_SESSION['user']['user_group_weight']) {
|
||||||
|
$this->apiOutput(400, ['error' => 'You cannot delete a user with an lower weight then yourself!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($user_data['user_uuid'] == $_SESSION['user']['user_uuid']) {
|
||||||
|
$this->apiOutput(400, ['error' => 'You cannot delete yourself, maybe some rope will do.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$query = "DELETE FROM vc_users WHERE user_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('s', $this->data['user_uuid']);
|
||||||
|
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => 'User successfully deleted']);
|
||||||
|
}
|
||||||
|
}
|
||||||
45
pub/api/classes/API_usersavatar.php
Normal file
45
pub/api/classes/API_usersavatar.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use api\classes\imageProcessor;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_usersavatar extends API
|
||||||
|
{
|
||||||
|
|
||||||
|
public function createUserImage($imageRestrictions)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
# Main image
|
||||||
|
$imageProcessor = new imageProcessor('user_profile_picture');
|
||||||
|
$imageProcessor->imageRestrictions = $imageRestrictions;
|
||||||
|
$imageProcessor->validateAndProcess();
|
||||||
|
$ImageData = $imageProcessor->returnBase64image();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->apiOutput(401, ['error' => 'Error: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ImageData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateUserImage()
|
||||||
|
{
|
||||||
|
$query = "UPDATE vc_users SET
|
||||||
|
user_profile_picture = ?,
|
||||||
|
user_profile_picture_thumbnail = ?
|
||||||
|
WHERE user_uuid = ?";
|
||||||
|
|
||||||
|
$stmt = $stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("sss",
|
||||||
|
$this->data['user_profile_picture'],
|
||||||
|
$this->data['user_profile_picture_thumbnail'],
|
||||||
|
$this->data['user_uuid']
|
||||||
|
);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
71
pub/api/classes/API_vendors.php
Normal file
71
pub/api/classes/API_vendors.php
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once 'API.php';
|
||||||
|
|
||||||
|
class API_vendors extends API
|
||||||
|
{
|
||||||
|
public function getVendors($returnBoolean = false)
|
||||||
|
{
|
||||||
|
list($query, $types, $params) = $this->buildDynamicQuery('vc_vendors');
|
||||||
|
|
||||||
|
$items = $this->generalGetFunction($query, $types, $params, $returnBoolean, 'Vendor');
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createVendor()
|
||||||
|
{
|
||||||
|
if (isset($this->data['vendor_image'])) {
|
||||||
|
$query = "INSERT INTO vc_vendors (vendor_uuid, vendor_name, vendor_slugify, vendor_description, vendor_enabled, vendor_create_timestamp, vendor_image) VALUES (UUID(), ?, ?, ?, ?, ?, ?)";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('ssssis', $this->data['vendor_name'], $this->data['vendor_slugify'], $this->data['vendor_description'], $this->data['vendor_enabled'], time(), $this->data['vendor_image']);
|
||||||
|
} else {
|
||||||
|
$query = "INSERT INTO vc_vendors (vendor_uuid, vendor_name, vendor_slugify, vendor_description, vendor_enabled, vendor_create_timestamp) VALUES (UUID(), ?, ?, ?, ?, ?)";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param('ssssi', $this->data['vendor_name'], $this->data['vendor_slugify'], $this->data['vendor_description'], $this->data['vendor_enabled'], time());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
$result = $this->getVendorSlugify();
|
||||||
|
if ($result->num_rows === 0) {
|
||||||
|
$this->apiOutput(500, ['error' => 'Something went wrong creating the vendor on the server.'], 'error_contact_support');
|
||||||
|
}
|
||||||
|
|
||||||
|
$platform_data = $result->fetch_assoc();
|
||||||
|
|
||||||
|
$this->apiOutput(200, ['success' => $platform_data], 'item_added');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getVendorSlugify()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM vc_vendors WHERE vendor_slugify = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("s", $this->data['vendor_slugify']);
|
||||||
|
$this->executeStatement($stmt);
|
||||||
|
return $stmt->get_result();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function editVendor()
|
||||||
|
{
|
||||||
|
if (isset($this->data['vendor_image'])) {
|
||||||
|
$query = "UPDATE vc_vendors SET vendor_name = ?, vendor_description = ?, vendor_enabled = ?, vendor_image = ?, vendor_modified_timestamp = ? WHERE vendor_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("ssisis", $this->data['vendor_name'], $this->data['vendor_description'], $this->data['vendor_enabled'], $this->data['vendor_image'], time(), $this->data['vendor_uuid']);
|
||||||
|
} else {
|
||||||
|
$query = "UPDATE vc_vendors SET vendor_name = ?, vendor_description = ?, vendor_enabled = ?, vendor_modified_timestamp = ? WHERE vendor_uuid = ?";
|
||||||
|
$stmt = $this->prepareStatement($query);
|
||||||
|
$stmt->bind_param("ssiis", $this->data['vendor_name'], $this->data['vendor_description'], $this->data['vendor_enabled'], time(), $this->data['vendor_uuid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->executeStatement($stmt)) {
|
||||||
|
$this->apiOutput(200, ['success' => 'Platform updated successfully.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
202
pub/api/classes/imageProcessor.php
Normal file
202
pub/api/classes/imageProcessor.php
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace api\classes;
|
||||||
|
class imageProcessor
|
||||||
|
{
|
||||||
|
public $postedFile = null;
|
||||||
|
private $imageTmpPath;
|
||||||
|
private $imageInfo;
|
||||||
|
|
||||||
|
public $imageRestrictions = [
|
||||||
|
'min_width' => 100,
|
||||||
|
'max_width' => 600,
|
||||||
|
'min_height' => 100,
|
||||||
|
'max_height' => 600,
|
||||||
|
'square' => false,
|
||||||
|
'allowed_types' => ['image/png', 'image/jpeg', 'image/webp'],
|
||||||
|
'max_size_kb' => 2048, // 2MB
|
||||||
|
'transparent' => false
|
||||||
|
];
|
||||||
|
|
||||||
|
private $finalImage = null;
|
||||||
|
|
||||||
|
public function __construct($imageName)
|
||||||
|
{
|
||||||
|
if (isset($_FILES[$imageName]) && $_FILES[$imageName]['error'] === UPLOAD_ERR_OK) {
|
||||||
|
$this->postedFile = $_FILES[$imageName];
|
||||||
|
$this->imageTmpPath = $this->postedFile['tmp_name'];
|
||||||
|
$this->imageInfo = getimagesize($this->imageTmpPath);
|
||||||
|
} elseif (isset($_POST['image_base64'])) {
|
||||||
|
$base64 = $_POST['image_base64'];
|
||||||
|
|
||||||
|
if (preg_match('/^data:(image\/\w+);base64,/', $base64, $matches)) {
|
||||||
|
$mimeType = $matches[1];
|
||||||
|
$base64 = substr($base64, strpos($base64, ',') + 1);
|
||||||
|
} else {
|
||||||
|
throw new Exception('Invalid image data.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$imageData = base64_decode($base64);
|
||||||
|
if ($imageData === false) {
|
||||||
|
throw new Exception('Invalid base64 image data.');
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create image directly from string (no file)
|
||||||
|
$srcImage = imagecreatefromstring($imageData);
|
||||||
|
if (!$srcImage) {
|
||||||
|
throw new Exception('Failed to create image from string.');
|
||||||
|
}
|
||||||
|
|
||||||
|
# Now you can get dimensions directly
|
||||||
|
$width = imagesx($srcImage);
|
||||||
|
$height = imagesy($srcImage);
|
||||||
|
|
||||||
|
# Store $srcImage in a class property, continue processing in-memory
|
||||||
|
$this->imageResource = $srcImage;
|
||||||
|
$this->imageInfo = [
|
||||||
|
'mime' => $mimeType,
|
||||||
|
'width' => $width,
|
||||||
|
'height' => $height,
|
||||||
|
'size' => strlen($imageData)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateAndProcess()
|
||||||
|
{
|
||||||
|
if (!$this->postedFile) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$width = $this->imageInfo[0];
|
||||||
|
$height = $this->imageInfo[1];
|
||||||
|
$mime = $this->imageInfo['mime'];
|
||||||
|
$fileSizeKB = filesize($this->imageTmpPath) / 1024;
|
||||||
|
|
||||||
|
if (!in_array($mime, $this->imageRestrictions['allowed_types'])) {
|
||||||
|
throw new Exception("Invalid image type: $mime");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fileSizeKB > $this->imageRestrictions['max_size_kb']) {
|
||||||
|
throw new Exception("Image exceeds max file size.");
|
||||||
|
}
|
||||||
|
|
||||||
|
# Resize to fit within min/max bounds
|
||||||
|
$resizedImage = $this->resizeToFitRestrictions($mime, $width, $height);
|
||||||
|
|
||||||
|
# Optionally square it
|
||||||
|
if ($this->imageRestrictions['square']) {
|
||||||
|
$resizedImage = $this->makeImageSquare($resizedImage, $mime);
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
switch ($mime) {
|
||||||
|
case 'image/jpeg':
|
||||||
|
imagejpeg($resizedImage);
|
||||||
|
break;
|
||||||
|
case 'image/png':
|
||||||
|
imagepng($resizedImage);
|
||||||
|
break;
|
||||||
|
case 'image/webp':
|
||||||
|
imagewebp($resizedImage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$this->finalImage = ob_get_clean();
|
||||||
|
|
||||||
|
imagedestroy($resizedImage);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function mimeSupportsTransparency($mime)
|
||||||
|
{
|
||||||
|
return in_array($mime, ['image/png', 'image/webp']);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setTransparentCanvas($image, $width, $height)
|
||||||
|
{
|
||||||
|
// Enable alpha blending and preserve alpha channel
|
||||||
|
imagealphablending($image, false);
|
||||||
|
imagesavealpha($image, true);
|
||||||
|
|
||||||
|
// Fill the image with a fully transparent color
|
||||||
|
$transparent = imagecolorallocatealpha($image, 0, 0, 0, 127);
|
||||||
|
imagefilledrectangle($image, 0, 0, $width, $height, $transparent);
|
||||||
|
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resizeToFitRestrictions($mime, $width, $height)
|
||||||
|
{
|
||||||
|
$minW = $this->imageRestrictions['min_width'];
|
||||||
|
$maxW = $this->imageRestrictions['max_width'];
|
||||||
|
$minH = $this->imageRestrictions['min_height'];
|
||||||
|
$maxH = $this->imageRestrictions['max_height'];
|
||||||
|
|
||||||
|
$srcImage = match ($mime) {
|
||||||
|
'image/jpeg' => imagecreatefromjpeg($this->imageTmpPath),
|
||||||
|
'image/png' => imagecreatefrompng($this->imageTmpPath),
|
||||||
|
'image/webp' => imagecreatefromwebp($this->imageTmpPath),
|
||||||
|
default => throw new Exception("Unsupported image type.")
|
||||||
|
};
|
||||||
|
|
||||||
|
# Determine new size
|
||||||
|
$newWidth = $width;
|
||||||
|
$newHeight = $height;
|
||||||
|
|
||||||
|
if ($width < $minW || $width > $maxW || $height < $minH || $height > $maxH) {
|
||||||
|
# Calculate scale factor based on limits
|
||||||
|
$widthScale = ($width < $minW) ? $minW / $width : ($width > $maxW ? $maxW / $width : 1);
|
||||||
|
$heightScale = ($height < $minH) ? $minH / $height : ($height > $maxH ? $maxH / $height : 1);
|
||||||
|
|
||||||
|
# Use the smallest scale to ensure both dimensions fit
|
||||||
|
$scale = min($widthScale, $heightScale);
|
||||||
|
|
||||||
|
$newWidth = round($width * $scale);
|
||||||
|
$newHeight = round($height * $scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
$resizedImage = imagecreatetruecolor($newWidth, $newHeight);
|
||||||
|
|
||||||
|
# keep transparent
|
||||||
|
if ($this->mimeSupportsTransparency($mime)) {
|
||||||
|
$this->setTransparentCanvas($resizedImage, $newWidth, $newHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
imagecopyresampled($resizedImage, $srcImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
|
||||||
|
imagedestroy($srcImage);
|
||||||
|
return $resizedImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function makeImageSquare($srcImage, $mime)
|
||||||
|
{
|
||||||
|
$width = imagesx($srcImage);
|
||||||
|
$height = imagesy($srcImage);
|
||||||
|
|
||||||
|
$size = min($width, $height);
|
||||||
|
$x = ($width - $size) / 2;
|
||||||
|
$y = ($height - $size) / 2;
|
||||||
|
|
||||||
|
$squareImage = imagecreatetruecolor($size, $size);
|
||||||
|
|
||||||
|
# keep transparent
|
||||||
|
if ($this->mimeSupportsTransparency($mime)) {
|
||||||
|
$this->setTransparentCanvas($squareImage, $size, $size);
|
||||||
|
}
|
||||||
|
|
||||||
|
imagecopyresampled($squareImage, $srcImage, 0, 0, $x, $y, $size, $size, $size, $size);
|
||||||
|
imagedestroy($srcImage);
|
||||||
|
|
||||||
|
return $squareImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function returnBase64image()
|
||||||
|
{
|
||||||
|
if ($this->finalImage) {
|
||||||
|
return base64_encode($this->finalImage);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
41
pub/api/v1/access-rights/index.php
Normal file
41
pub/api/v1/access-rights/index.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_permissions;
|
||||||
|
use api\classes\API_usergroups;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_permissions.php';
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_usergroups.php';
|
||||||
|
|
||||||
|
$API_permissions = new API_permissions();
|
||||||
|
$API_usergroups = new API_usergroups();
|
||||||
|
|
||||||
|
if ($API_permissions->request_method === 'GET') {
|
||||||
|
# to be made, get all the access-rights and implement the builder
|
||||||
|
|
||||||
|
} elseif ($API_permissions->request_method === 'PUT') {
|
||||||
|
|
||||||
|
# when called from the frontend will not be forwarding to a url since when its called from the frontend it doesnt need a redirection
|
||||||
|
$API_permissions->return_url = false;
|
||||||
|
|
||||||
|
$API_permissions->checkPermissions('admin-access-control-permissions', 'RW');
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'permission_uuid' => ['type' => 'uuid'],
|
||||||
|
'user_group_uuid' => ['type' => 'uuid'],
|
||||||
|
'permission_value' => ['type' => 'enum', 'values' => ['NA', 'RO', 'RW']],
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_permissions->validateData($requiredFields);
|
||||||
|
|
||||||
|
# check if the permission exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'permission_uuid', 1 => $API_permissions->data['permission_uuid']]]];
|
||||||
|
$API_permissions->getPermission();
|
||||||
|
|
||||||
|
# check if the user_group_uuid exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'user_group_uuid', 1 => $API_permissions->data['user_group_uuid']]]];
|
||||||
|
$API_usergroups->getUsergroup();
|
||||||
|
|
||||||
|
# Update the permission
|
||||||
|
$API_permissions->updateAccessRights();
|
||||||
|
}
|
||||||
29
pub/api/v1/customers/companies/activate/index.php
Normal file
29
pub/api/v1/customers/companies/activate/index.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_companies;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_companies.php';
|
||||||
|
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API_companies = new API_companies();
|
||||||
|
|
||||||
|
|
||||||
|
if ($API_companies->request_method === 'PUT') {
|
||||||
|
$API_companies->checkPermissions('customer-companies', 'RW');
|
||||||
|
|
||||||
|
# when called from the frontend will not be forwarding to a url since when its called from the frontend it doesnt need a redirection
|
||||||
|
$API_companies->return_url = false;
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'company_uuid' => ['type' => 'uuid'],
|
||||||
|
'company_state' => ['type' => 'enum', 'values' => ['active', 'imported', 'orphaned']]
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_companies->validateData($requiredFields);
|
||||||
|
|
||||||
|
$API_companies->updateCompanyState();
|
||||||
|
|
||||||
|
}
|
||||||
66
pub/api/v1/customers/companies/sync/index.php
Normal file
66
pub/api/v1/customers/companies/sync/index.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_inserve;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_inserve.php';
|
||||||
|
|
||||||
|
$API_inserve = new API_inserve();
|
||||||
|
$API_inserve->setupConnection();
|
||||||
|
|
||||||
|
if ($API_inserve->request_method === 'POST') {
|
||||||
|
# Code below will retrieve all the companies and create or update it in the database
|
||||||
|
#
|
||||||
|
|
||||||
|
$API_inserve->checkPermissions('customer-companies', 'RW');
|
||||||
|
|
||||||
|
$allCompanies = [];
|
||||||
|
$page = 1;
|
||||||
|
|
||||||
|
do {
|
||||||
|
$result = $API_inserve->companies($page);
|
||||||
|
|
||||||
|
if (!isset($result['data']) || empty($result['data'])) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($result['data'] as $item) {
|
||||||
|
$allCompanies[] = [
|
||||||
|
'id' => $item['id'],
|
||||||
|
'name' => $item['name'],
|
||||||
|
'debtor_code' => $item['debtor_code'],
|
||||||
|
'archived_at' => $item['archived_at']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$page++;
|
||||||
|
|
||||||
|
} while ($result['next_page_url'] !== null);
|
||||||
|
|
||||||
|
foreach ($allCompanies as $company) {
|
||||||
|
$source_uuid = $API_inserve->inserve_source_uuid;
|
||||||
|
$company_id = $company['id'];
|
||||||
|
$debtor_code = $company['debtor_code'];
|
||||||
|
$company_name = $company['name'];
|
||||||
|
$created_at = time();
|
||||||
|
|
||||||
|
# Add or modify the company if it is not archived
|
||||||
|
if ($company['archived_at'] == null) {
|
||||||
|
$query = "INSERT INTO companies (source_uuid, company_source_id, company_source_id2, company_name, company_create_timestamp)
|
||||||
|
VALUES (?, ?, ?, ?, ?)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
company_name = VALUES(company_name),
|
||||||
|
company_source_id2 = VALUES(company_source_id2),
|
||||||
|
company_modified_timestamp = VALUES(company_create_timestamp)";
|
||||||
|
$stmt = $API_inserve->prepareStatement($query);
|
||||||
|
$stmt->bind_param('ssssi', $source_uuid, $company_id, $debtor_code, $company_name, $created_at);
|
||||||
|
$API_inserve->executeStatement($stmt);
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$API_inserve->apiOutput(200, ['success' => 'Sync is done successfully']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
118
pub/api/v1/devices/files/index.php
Normal file
118
pub/api/v1/devices/files/index.php
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_devices;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_devices.php';
|
||||||
|
|
||||||
|
$API_devices = new API_devices();
|
||||||
|
|
||||||
|
if ($API_devices->request_method === 'POST') {
|
||||||
|
|
||||||
|
$API_devices->checkPermissions('admin-devices-files', 'RW');
|
||||||
|
|
||||||
|
# when called from the frontend will not be forwarding to a url since when its called from the frontend it doesnt need a redirection
|
||||||
|
$API_devices->return_url = false;
|
||||||
|
|
||||||
|
$device_slugify = isset($_POST['device_slugify']) ? preg_replace('/[^a-zA-Z0-9_-]/', '_', $_POST['device_slugify']) : '';
|
||||||
|
$filetype = $_POST['filetype'] ?? '';
|
||||||
|
|
||||||
|
$allowedFiletypes = ['documents' => 'pdf', 'firmware' => 'rom'];
|
||||||
|
if (!array_key_exists($filetype, $allowedFiletypes)) {
|
||||||
|
$API_devices->apiOutput(400, ['error' => 'Invalid file type']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($_FILES['file']) || $_FILES['file']['error'] !== UPLOAD_ERR_OK) {
|
||||||
|
$API_devices->apiOutput(400, ['error' => 'No file uploaded or upload error']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = basename($_FILES['file']['name']);
|
||||||
|
$filename = preg_replace('/[^a-zA-Z0-9_\.\-]/', '_', $filename);
|
||||||
|
$file_extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
|
||||||
|
|
||||||
|
$expectedExtension = $allowedFiletypes[$filetype];
|
||||||
|
if ($file_extension !== $expectedExtension) {
|
||||||
|
$API_devices->apiOutput(415, ['error' => "Invalid file extension. Expected: $expectedExtension"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||||
|
$detectedMime = finfo_file($finfo, $_FILES['file']['tmp_name']);
|
||||||
|
finfo_close($finfo);
|
||||||
|
|
||||||
|
$expectedMimeTypes = [
|
||||||
|
'pdf' => 'application/pdf',
|
||||||
|
'rom' => 'application/octet-stream'
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!str_starts_with($detectedMime, $expectedMimeTypes[$expectedExtension])) {
|
||||||
|
$API_devices->apiOutput(415, ['error' => 'Invalid MIME type: ' . $detectedMime]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$destination_dir = $_SERVER['DOCUMENT_ROOT'] . '/data/devices/' . $device_slugify . '/' . $filetype;
|
||||||
|
if (!is_dir($destination_dir) && !mkdir($destination_dir, 0775, true) && !is_dir($destination_dir)) {
|
||||||
|
$API_devices->apiOutput(500, ['error' => 'Failed to create directory']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$destination = $destination_dir . '/' . $filename;
|
||||||
|
if (file_exists($destination)) {
|
||||||
|
$API_devices->apiOutput(409, ['error' => 'File already exists']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (move_uploaded_file($_FILES['file']['tmp_name'], $destination)) {
|
||||||
|
chmod($destination, 0644); // Set safe permissions
|
||||||
|
$API_devices->apiOutput(200, ['success' => 'File uploaded succcessfully']);
|
||||||
|
} else {
|
||||||
|
$API_devices->apiOutput(500, ['error' => 'Failed to move uploaded file']);
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif ($API_devices->request_method === 'DELETE') {
|
||||||
|
|
||||||
|
$API_devices->checkPermissions('admin-devices-files', 'RW');
|
||||||
|
|
||||||
|
# when called from the frontend will not be forwarding to a url since when its called from the frontend it doesnt need a redirection
|
||||||
|
$API_devices->return_url = false;
|
||||||
|
|
||||||
|
$relativePath = $_POST['file_name'] ?? '';
|
||||||
|
|
||||||
|
// Ensure it's not empty and doesn't contain null byte or backslashes
|
||||||
|
if (empty($relativePath) || str_contains($relativePath, "\0") || str_contains($relativePath, '\\')) {
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Invalid path input']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalize base root
|
||||||
|
$root = realpath($_SERVER['DOCUMENT_ROOT'] . '/data/devices');
|
||||||
|
if (!$root) {
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Invalid devices root']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve full path
|
||||||
|
$requestedPath = realpath($_SERVER['DOCUMENT_ROOT'] . $relativePath);
|
||||||
|
|
||||||
|
// Validate resolved path
|
||||||
|
if (!$requestedPath || strpos($requestedPath, $root) !== 0) {
|
||||||
|
http_response_code(403);
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Access denied']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if file exists and is a regular file
|
||||||
|
if (!is_file($requestedPath)) {
|
||||||
|
http_response_code(404);
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'File does not exist']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to delete
|
||||||
|
if (unlink($requestedPath)) {
|
||||||
|
echo json_encode(['status' => 'success', 'message' => 'File deleted']);
|
||||||
|
} else {
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode(['status' => 'error', 'message' => 'Failed to delete file']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
120
pub/api/v1/devices/index.php
Normal file
120
pub/api/v1/devices/index.php
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_devices;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_devices.php';
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/imageProcessor.php';
|
||||||
|
|
||||||
|
$API_devices = new API_devices();
|
||||||
|
|
||||||
|
if ($API_devices->request_method === 'GET') {
|
||||||
|
|
||||||
|
# GET the devices
|
||||||
|
|
||||||
|
$API_devices->checkPermissions('admin-devices', 'RO');
|
||||||
|
|
||||||
|
} elseif ($API_devices->request_method === 'POST') {
|
||||||
|
|
||||||
|
# create an new device
|
||||||
|
|
||||||
|
$API_devices->checkPermissions('admin-devices', 'RW');
|
||||||
|
|
||||||
|
$ImageData = $API_devices->createDeviceImage(['min_width' => 500, 'max_width' => 1000, 'min_height' => 500, 'max_height' => 1000, 'square' => true, 'allowed_types' => ['image/png'], 'max_size_kb' => 1024, 'transparent' => true]);
|
||||||
|
$ImageDataThumbnail = $API_devices->createDeviceImage(['min_width' => 64, 'max_width' => 64, 'min_height' => 64, 'max_height' => 64, 'square' => true, 'allowed_types' => ['image/png'], 'max_size_kb' => 1024, 'transparent' => true]);
|
||||||
|
$API_devices->postedData['device_eol'] = $_POST['device_eol'] !== ''
|
||||||
|
? DateTime::createFromFormat('d/m/Y', $_POST['device_eol'])?->getTimestamp()
|
||||||
|
: null;
|
||||||
|
$API_devices->postedData['device_extensions'] = isset($_POST['device_extensions']) ? json_encode($_POST['device_extensions']) : '[""]';
|
||||||
|
$API_devices->postedData['device_extra'] = preg_replace('/\s+/', '', str_replace(["\r", "\n"], '', $_POST['device_extra'] ?? '{}'));
|
||||||
|
|
||||||
|
if ($ImageData) {
|
||||||
|
$API_devices->postedData['device_image'] = $ImageData;
|
||||||
|
}
|
||||||
|
if ($ImageDataThumbnail) {
|
||||||
|
$API_devices->postedData['device_image_thumbnail'] = $ImageDataThumbnail;
|
||||||
|
}
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'device_vendor_uuid' => ['type' => 'uuid'],
|
||||||
|
'device_type' => ['type' => 'enum', 'values' => ['base', 'handset', 'module', 'phone']],
|
||||||
|
'device_name' => ['type' => 'string'],
|
||||||
|
'device_slugify' => ['type' => 'slugify'],
|
||||||
|
'device_enabled' => ['type' => 'boolean'],
|
||||||
|
'device_notes' => ['type' => 'string'],
|
||||||
|
'device_eol' => ['type' => 'timestamp'],
|
||||||
|
'device_extensions' => ['type' => 'json'],
|
||||||
|
'device_extra' => ['type' => 'string'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$optionalFields = [
|
||||||
|
'device_image' => ['type' => 'base64'],
|
||||||
|
'device_image_thumbnail' => ['type' => 'base64']
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_devices->validateData($requiredFields, $optionalFields);
|
||||||
|
|
||||||
|
$API_devices->createDevice();
|
||||||
|
|
||||||
|
} elseif ($API_devices->request_method === 'PUT') {
|
||||||
|
|
||||||
|
# Edit the device
|
||||||
|
$API_devices->checkPermissions('admin-devices', 'RW');
|
||||||
|
|
||||||
|
# process the posted image (if any)
|
||||||
|
$ImageData = $API_devices->createDeviceImage(['min_width' => 500, 'max_width' => 1000, 'min_height' => 500, 'max_height' => 1000, 'square' => true, 'allowed_types' => ['image/png'], 'max_size_kb' => 1024, 'transparent' => true]);
|
||||||
|
$ImageDataThumbnail = $API_devices->createDeviceImage(['min_width' => 64, 'max_width' => 64, 'min_height' => 64, 'max_height' => 64, 'square' => true, 'allowed_types' => ['image/png'], 'max_size_kb' => 1024, 'transparent' => true]);
|
||||||
|
$API_devices->postedData['device_eol'] = $_POST['device_eol'] !== ''
|
||||||
|
? DateTime::createFromFormat('d/m/Y', $_POST['device_eol'])?->getTimestamp()
|
||||||
|
: null;
|
||||||
|
$API_devices->postedData['device_extensions'] = isset($_POST['device_extensions']) ? json_encode($_POST['device_extensions']) : '[""]';
|
||||||
|
$API_devices->postedData['device_extra'] = preg_replace('/\s+/', '', str_replace(["\r", "\n"], '', $_POST['device_extra'] ?? '{}'));
|
||||||
|
|
||||||
|
if ($ImageData) {
|
||||||
|
$API_devices->postedData['device_image'] = $ImageData;
|
||||||
|
}
|
||||||
|
if ($ImageDataThumbnail) {
|
||||||
|
$API_devices->postedData['device_image_thumbnail'] = $ImageDataThumbnail;
|
||||||
|
}
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'device_uuid' => ['type' => 'uuid'],
|
||||||
|
'device_vendor_uuid' => ['type' => 'uuid'],
|
||||||
|
'device_name' => ['type' => 'string'],
|
||||||
|
'device_enabled' => ['type' => 'boolean'],
|
||||||
|
'device_notes' => ['type' => 'string'],
|
||||||
|
'device_eol' => ['type' => 'timestamp'],
|
||||||
|
'device_extensions' => ['type' => 'json'],
|
||||||
|
'device_extra' => ['type' => 'string'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$optionalFields = [
|
||||||
|
'device_image' => ['type' => 'base64'],
|
||||||
|
'device_image_thumbnail' => ['type' => 'base64']
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_devices->validateData($requiredFields, $optionalFields);
|
||||||
|
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'device_uuid', 1 => $API_devices->data['device_uuid']]]];
|
||||||
|
$API_devices->getDevices();
|
||||||
|
|
||||||
|
$API_devices->updateDevice();
|
||||||
|
|
||||||
|
} elseif ($API_devices->request_method === 'DELETE') {
|
||||||
|
|
||||||
|
# delete an device
|
||||||
|
|
||||||
|
$API_devices->checkPermissions('admin-devices', 'RW');
|
||||||
|
|
||||||
|
# when called from the frontend will not be forwarding to a url since when its called from the frontend it doesnt need a redirection
|
||||||
|
$API_devices->return_url = false;
|
||||||
|
|
||||||
|
$requiredFields = ['device_uuid' => ['type' => 'uuid']];
|
||||||
|
$API_devices->validateData($requiredFields);
|
||||||
|
|
||||||
|
# check if the device exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'device_uuid', 1 => $API_devices->data['device_uuid']]]];
|
||||||
|
|
||||||
|
# Delete the device from the database.
|
||||||
|
$API_devices->deleteDevice();
|
||||||
|
}
|
||||||
43
pub/api/v1/mailsettings/index.php
Normal file
43
pub/api/v1/mailsettings/index.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_mailsettings;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_mailsettings.php';
|
||||||
|
|
||||||
|
$API_mailsettings = new API_mailsettings();
|
||||||
|
|
||||||
|
if ($API_mailsettings->request_method === 'PUT') {
|
||||||
|
# Edit the mailsettings of the platform
|
||||||
|
|
||||||
|
$API_mailsettings->checkPermissions('admin-mailsettings', 'RW');
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'portal_uuid' => ['type' => 'uuid'],
|
||||||
|
'mail_from_name' => ['type' => 'string'],
|
||||||
|
'mail_from_address' => ['type' => 'email'],
|
||||||
|
'mail_smtp_host' => ['type' => 'string'],
|
||||||
|
'mail_smtp_secure' => ['type' => 'enum', 'values' => ['tls', 'ssl', 'no']],
|
||||||
|
'mail_smtp_port' => ['type' => 'int', 'min' => 4, 'max' => 65535],
|
||||||
|
'mail_smtp_auth' => ['type' => 'boolean'],
|
||||||
|
'mail_smtp_user' => ['type' => 'email'],
|
||||||
|
'mail_smtp_pass' => ['type' => 'string']
|
||||||
|
];
|
||||||
|
# check if the password is changed
|
||||||
|
$updatePassword = str_contains($API_mailsettings->postedData['mail_smtp_pass'], '******') ? false : true;
|
||||||
|
if ($updatePassword) {
|
||||||
|
if (strlen($API_mailsettings->postedData['mail_smtp_pass']) < 12) {
|
||||||
|
$API_mailsettings->apiOutput(400, ['error' => 'Password too short']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/^(.)\1{5,}$/', $API_mailsettings->postedData['mail_smtp_pass'])) {
|
||||||
|
$API_mailsettings->apiOutput(400, ['error' => 'Password insecure']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$API_mailsettings->validateData($requiredFields);
|
||||||
|
|
||||||
|
# Update the permission
|
||||||
|
$API_mailsettings->updateMailSettings($updatePassword);
|
||||||
|
|
||||||
|
}
|
||||||
38
pub/api/v1/office/stompjes/index.php
Normal file
38
pub/api/v1/office/stompjes/index.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_office_stompjes;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_office_stompjes.php';
|
||||||
|
|
||||||
|
$API_office_stompjes = new API_office_stompjes();
|
||||||
|
|
||||||
|
|
||||||
|
if ($API_office_stompjes->request_method === 'POST') {
|
||||||
|
$API_office_stompjes->checkPermissions('ofice-stompjes-canstomp', 'RW');
|
||||||
|
|
||||||
|
$API_office_stompjes->return_url = false;
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'user_uuid' => ['type' => 'uuid']
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_office_stompjes->validateData($requiredFields);
|
||||||
|
|
||||||
|
$modules = $API_office_stompjes->addStomp();
|
||||||
|
|
||||||
|
$API_office_stompjes->apiOutput($code = 200, ['success' => 'stomp added successfully.']);
|
||||||
|
} elseif ($API_office_stompjes->request_method === 'DELETE') {
|
||||||
|
|
||||||
|
# Only superuser can delete permission due to fact that the backend needs programming when setting a permission
|
||||||
|
$API_office_stompjes->checkPermissions('ofice-stompjes', 'RW');
|
||||||
|
|
||||||
|
# when called from the frontend will not be forwarding to a url since when its called from the frontend it doesnt need a redirection
|
||||||
|
$API_office_stompjes->return_url = false;
|
||||||
|
|
||||||
|
$requiredFields = ['stomp_uuid' => ['type' => 'uuid']];
|
||||||
|
$API_office_stompjes->validateData($requiredFields);
|
||||||
|
|
||||||
|
# delete permission
|
||||||
|
$API_office_stompjes->deleteStomp();
|
||||||
|
}
|
||||||
87
pub/api/v1/permissions/index.php
Normal file
87
pub/api/v1/permissions/index.php
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_permissions;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_permissions.php';
|
||||||
|
|
||||||
|
$API_permissions = new API_permissions();
|
||||||
|
|
||||||
|
if ($API_permissions->request_method === 'GET') {
|
||||||
|
|
||||||
|
# Retrieve all the permissions a user and return them.
|
||||||
|
$API_permissions->checkPermissions('admin-access-control-permissions', 'RO');
|
||||||
|
|
||||||
|
$requiredFields = [];
|
||||||
|
$optionalFields = [
|
||||||
|
'permission_uuid' => ['type' => 'uuid'],
|
||||||
|
'permission_name' => ['type' => 'string'],
|
||||||
|
'permission_slugify' => ['type' => 'slugify'],
|
||||||
|
'permission_description' => ['type' => 'string'],
|
||||||
|
'permission_create_timestamp' => ['type' => 'timestamp'],
|
||||||
|
'permission_modified_timestamp' => ['type' => 'timestamp']
|
||||||
|
];
|
||||||
|
$API_permissions->validateData($requiredFields, $optionalFields);
|
||||||
|
$permissions = $API_permissions->getPermission();
|
||||||
|
|
||||||
|
$API_permissions->apiOutput($code = 200, ['success' => $permissions], 'permission_created');
|
||||||
|
|
||||||
|
} elseif ($API_permissions->request_method === 'POST') {
|
||||||
|
|
||||||
|
# Only superuser can create permission due to fact that the backend needs programming when setting a permission
|
||||||
|
|
||||||
|
if (!$API_permissions->isSuperuser()) {
|
||||||
|
$API_permissions->apiOutput(401, ['error' => 'You are not authorized to access this resource.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'permission_name' => ['type' => 'string', 'min' => 6, 'max' => 255],
|
||||||
|
'permission_slugify' => ['type' => 'slugify', 'min' => 6, 'max' => 255],
|
||||||
|
'permission_description' => ['type' => 'string', 'min' => 1, 'max' => 512],
|
||||||
|
'module_uuid' => ['type' => 'uuid'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_permissions->validateData($requiredFields);
|
||||||
|
$API_permissions->createPermission();
|
||||||
|
|
||||||
|
} elseif ($API_permissions->request_method === 'PUT') {
|
||||||
|
|
||||||
|
# Update the permission name and description
|
||||||
|
$API_permissions->checkPermissions('admin-access-control-permissions', 'RW');
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'permission_uuid' => ['type' => 'uuid'],
|
||||||
|
'permission_name' => ['type' => 'string', 'min' => 6, 'max' => 255],
|
||||||
|
'permission_description' => ['type' => 'string', 'min' => 1, 'max' => 512],
|
||||||
|
'module_uuid' => ['type' => 'uuid'],
|
||||||
|
];
|
||||||
|
$API_permissions->validateData($requiredFields);
|
||||||
|
|
||||||
|
# check if the permission exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'permission_uuid', 1 => $API_permissions->data['permission_uuid']]]];
|
||||||
|
$API_permissions->getPermission();
|
||||||
|
|
||||||
|
# Update the permission
|
||||||
|
$API_permissions->updatePermission();
|
||||||
|
|
||||||
|
} elseif ($API_permissions->request_method === 'DELETE') {
|
||||||
|
|
||||||
|
# Only superuser can delete permission due to fact that the backend needs programming when setting a permission
|
||||||
|
if (!$API_permissions->isSuperuser()) {
|
||||||
|
$API_permissions->apiOutput(401, ['error' => 'You are not authorized to access this resource.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
# when called from the frontend will not be forwarding to a url since when its called from the frontend it doesnt need a redirection
|
||||||
|
$API_permissions->return_url = false;
|
||||||
|
|
||||||
|
$requiredFields = ['permission_uuid' => ['type' => 'uuid']];
|
||||||
|
$API_permissions->validateData($requiredFields);
|
||||||
|
|
||||||
|
# check if the permission exists
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'permission_uuid', 1 => $API_permissions->data['permission_uuid']]]];
|
||||||
|
$API_permissions->getPermission();
|
||||||
|
|
||||||
|
# delete permission
|
||||||
|
$API_permissions->deletePermission();
|
||||||
|
}
|
||||||
94
pub/api/v1/platforms/index.php
Normal file
94
pub/api/v1/platforms/index.php
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_platforms;
|
||||||
|
use api\classes\imageProcessor;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_platforms.php';
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/imageProcessor.php';
|
||||||
|
|
||||||
|
$API_platforms = new API_platforms();
|
||||||
|
|
||||||
|
if ($API_platforms->request_method === 'GET') {
|
||||||
|
# get all the platforms
|
||||||
|
$API_platforms->checkPermissions('admin-platforms', 'RO');
|
||||||
|
|
||||||
|
} elseif ($API_platforms->request_method === 'POST') {
|
||||||
|
# create a new platform
|
||||||
|
|
||||||
|
$API_platforms->checkPermissions('admin-platforms', 'RW');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$imageProcessor = new imageProcessor('platform_image');
|
||||||
|
$imageProcessor->imageRestrictions = [
|
||||||
|
'min_width' => 200,
|
||||||
|
'max_width' => 200,
|
||||||
|
'min_height' => 200,
|
||||||
|
'max_height' => 200,
|
||||||
|
'square' => true,
|
||||||
|
'allowed_types' => ['image/png'],
|
||||||
|
'max_size_kb' => 1024
|
||||||
|
];
|
||||||
|
|
||||||
|
$imageProcessor->validateAndProcess();
|
||||||
|
$finalImageData = $imageProcessor->returnBase64image();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$API_platforms->apiOutput(401, ['error' => 'Error: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$API_platforms->postedData['platform_image'] = $finalImageData;
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'platform_name' => ['type' => 'string'],
|
||||||
|
'platform_slugify' => ['type' => 'slugify'],
|
||||||
|
'platform_enabled' => ['type' => 'boolean'],
|
||||||
|
'platform_description' => ['type' => 'string'],
|
||||||
|
];
|
||||||
|
$optionalFields = ['platform_image' => ['type' => 'string']];
|
||||||
|
|
||||||
|
$API_platforms->validateData($requiredFields, $optionalFields);
|
||||||
|
|
||||||
|
$API_platforms->createPlatforms();
|
||||||
|
} elseif ($API_platforms->request_method === 'PUT') {
|
||||||
|
|
||||||
|
# edit a platform
|
||||||
|
$API_platforms->checkPermissions('admin-platforms', 'RW');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$imageProcessor = new imageProcessor('platform_image');
|
||||||
|
$imageProcessor->imageRestrictions = [
|
||||||
|
'min_width' => 200,
|
||||||
|
'max_width' => 200,
|
||||||
|
'min_height' => 200,
|
||||||
|
'max_height' => 200,
|
||||||
|
'square' => true,
|
||||||
|
'allowed_types' => ['image/png'],
|
||||||
|
'max_size_kb' => 1024
|
||||||
|
];
|
||||||
|
$imageProcessor->validateAndProcess();
|
||||||
|
$finalImageData = $imageProcessor->returnBase64image();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$API_platforms->apiOutput(401, ['error' => 'Error: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($finalImageData) {
|
||||||
|
$API_platforms->postedData['platform_image'] = $finalImageData;
|
||||||
|
}
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'platform_uuid' => ['type' => 'uuid'],
|
||||||
|
'platform_name' => ['type' => 'string'],
|
||||||
|
'platform_enabled' => ['type' => 'boolean'],
|
||||||
|
'platform_description' => ['type' => 'string'],
|
||||||
|
];
|
||||||
|
$optionalFields = ['platform_image' => ['type' => 'string']];
|
||||||
|
|
||||||
|
|
||||||
|
$API_platforms->validateData($requiredFields, $optionalFields);
|
||||||
|
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'platform_uuid', 1 => $API_platforms->data['platform_uuid']]]];
|
||||||
|
$API_platforms->getPlatforms();
|
||||||
|
|
||||||
|
$API_platforms->editPlatforms();
|
||||||
|
|
||||||
|
}
|
||||||
28
pub/api/v1/portalsettings/index.php
Normal file
28
pub/api/v1/portalsettings/index.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_portalsettings;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_portalsettings.php';
|
||||||
|
|
||||||
|
$API_portalsettings = new API_portalsettings();
|
||||||
|
|
||||||
|
if ($API_portalsettings->request_method === 'PUT') {
|
||||||
|
|
||||||
|
# Edit the portal settings of the platform
|
||||||
|
|
||||||
|
$API_portalsettings->checkPermissions('admin-portalsettings', 'RW');
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'portal_uuid' => ['type' => 'uuid'],
|
||||||
|
'portal_name' => ['type' => 'string'],
|
||||||
|
'portal_provider_name' => ['type' => 'string'],
|
||||||
|
'admin_auth_methods' => ['type' => 'string']
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_portalsettings->validateData($requiredFields);
|
||||||
|
|
||||||
|
# Update the permission
|
||||||
|
$API_portalsettings->updatePortalSettings();
|
||||||
|
|
||||||
|
}
|
||||||
52
pub/api/v1/servers/index.php
Normal file
52
pub/api/v1/servers/index.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_servers;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_servers.php';
|
||||||
|
|
||||||
|
$API_servers = new API_servers();
|
||||||
|
|
||||||
|
if ($API_servers->request_method === 'POST') {
|
||||||
|
$API_servers->checkPermissions('servers', 'RW');
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'server_vm_id' => ['type' => 'string'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$optionalFields = [
|
||||||
|
'server_vm_host_id' => ['type' => 'string'],
|
||||||
|
'server_vm_host_name' => ['type' => 'string'],
|
||||||
|
'company_uuid' => ['type' => 'string'],
|
||||||
|
'server_power_state' => ['type' => 'enum', 'values' => ['Running', 'Off']],
|
||||||
|
'server_state' => ['type' => 'enum', 'values' => ['new', 'active', 'deleted', 'trial', 'disabled']],
|
||||||
|
'server_hostname' => ['type' => 'string'],
|
||||||
|
'server_os' => ['type' => 'string'],
|
||||||
|
'server_cpu' => ['type' => 'int'],
|
||||||
|
'server_memory' => ['type' => 'int'],
|
||||||
|
'server_memory_demand' => ['type' => 'int'],
|
||||||
|
'server_disks' => ['type' => 'json'],
|
||||||
|
'server_ipv4' => ['type' => 'json'],
|
||||||
|
'server_ipv6' => ['type' => 'json'],
|
||||||
|
'server_vm_generation' => ['type' => 'int'],
|
||||||
|
'server_vm_snapshot' => ['type' => 'int'],
|
||||||
|
'server_licenses' => ['type' => 'json'],
|
||||||
|
'server_backup' => ['type' => 'json'],
|
||||||
|
'server_description' => ['type' => 'string'],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isset($API_servers->postedData['servers'])) {
|
||||||
|
// multiple servers are posted
|
||||||
|
$allServers = $API_servers->postedData['servers'];
|
||||||
|
|
||||||
|
foreach ($allServers as $server) {
|
||||||
|
$API_servers->processServerData($server, $requiredFields, $optionalFields);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Single server update
|
||||||
|
$API_servers->processServerData($API_servers->postedData, $requiredFields, $optionalFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
$API_servers->apiOutput(200, ['success' => "Server(s) modified or updated successfully."]);
|
||||||
|
}
|
||||||
26
pub/api/v1/sources/inserve/index.php
Normal file
26
pub/api/v1/sources/inserve/index.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_inserve;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_inserve.php';
|
||||||
|
|
||||||
|
$API_inserve = new API_inserve();
|
||||||
|
$API_inserve->setupConnection();
|
||||||
|
|
||||||
|
|
||||||
|
if ($API_inserve->request_method === 'GET') {
|
||||||
|
|
||||||
|
if ($_GET['action'] = 'auth/me') {
|
||||||
|
|
||||||
|
# This api call, when called from the frontend will not be forwarding to a url.
|
||||||
|
$API_inserve->return_url = false;
|
||||||
|
$auth = $API_inserve->authMe();
|
||||||
|
|
||||||
|
http_response_code($API_inserve->httpCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
32
pub/api/v1/sources/inserve/subscriptions/index.php
Normal file
32
pub/api/v1/sources/inserve/subscriptions/index.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_inserve;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_inserve.php';
|
||||||
|
|
||||||
|
|
||||||
|
$API_inserve = new API_inserve();
|
||||||
|
|
||||||
|
if ($API_inserve->request_method === 'GET') {
|
||||||
|
|
||||||
|
if ($_GET['action'] == 'sync-companies') {
|
||||||
|
# This syncs the company id's from Sentri to the Inserve cloudDistributor
|
||||||
|
# These are the same id's but it Inserve requires it to be synced to the cloudDistributor
|
||||||
|
$API_inserve->checkPermissions('servers', 'RW');
|
||||||
|
$API_inserve->setupConnection();
|
||||||
|
|
||||||
|
$API_inserve->syncCompaniesFromSentri();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($_GET['action'] == 'sync-subscriptions') {
|
||||||
|
$API_inserve->checkPermissions('servers', 'RW');
|
||||||
|
$API_inserve->setupConnection();
|
||||||
|
|
||||||
|
$API_inserve->syncServerLicencesToInserve();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
37
pub/api/v1/system/modules/index.php
Normal file
37
pub/api/v1/system/modules/index.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_system_modules;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_system_modules.php';
|
||||||
|
|
||||||
|
$API_system_modules = new API_system_modules();
|
||||||
|
|
||||||
|
if ($API_system_modules->request_method === 'GET') {
|
||||||
|
# this part here is not tested (the whole GET part)
|
||||||
|
$API_system_modules->checkPermissions('admin-modules', 'RO');
|
||||||
|
|
||||||
|
$requiredFields = [];
|
||||||
|
$API_system_modules->validateData($requiredFields);
|
||||||
|
|
||||||
|
$modules = $API_system_modules->getModules();
|
||||||
|
|
||||||
|
$API_system_modules->apiOutput($code = 200, ['success' => $modules], '');
|
||||||
|
|
||||||
|
} elseif ($API_system_modules->request_method === 'PUT') {
|
||||||
|
# Enable or disable a module
|
||||||
|
$API_system_modules->checkPermissions('admin-modules', 'RW');
|
||||||
|
|
||||||
|
# This api call, when called from the frontend will not be forwarding to a url.
|
||||||
|
$API_system_modules->return_url = false;
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'module_uuid' => ['type' => 'uuid'],
|
||||||
|
'module_enabled' => ['type' => 'boolean'],
|
||||||
|
];
|
||||||
|
$API_system_modules->validateData($requiredFields);
|
||||||
|
|
||||||
|
$API_system_modules->enableModule();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
30
pub/api/v1/system/sources/inserve/index.php
Normal file
30
pub/api/v1/system/sources/inserve/index.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_system_sources;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_system_sources.php';
|
||||||
|
|
||||||
|
$API_system_sources = new API_system_sources();
|
||||||
|
|
||||||
|
if ($API_system_sources->request_method === 'POST') {
|
||||||
|
# Enable or disable a module
|
||||||
|
$API_system_sources->checkPermissions('admin-sources', 'RW');
|
||||||
|
|
||||||
|
if ($_POST['source_name'] == 'inserve') {
|
||||||
|
$requiredFields = [
|
||||||
|
'source_name' => ['type' => 'string'],
|
||||||
|
'source_url' => ['type' => 'string'],
|
||||||
|
'source_auth_token' => ['type' => 'string'],
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$API_system_sources->apiOutput(400, ['error' => 'Error: no valid source_name posted']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$API_system_sources->validateData($requiredFields);
|
||||||
|
|
||||||
|
if ($_POST['source_name'] == 'inserve') {
|
||||||
|
$API_system_sources->inserveUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
67
pub/api/v1/user-groups/index.php
Normal file
67
pub/api/v1/user-groups/index.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_usergroups;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_usergroups.php';
|
||||||
|
|
||||||
|
|
||||||
|
$API_usergroups = new API_usergroups();
|
||||||
|
|
||||||
|
if ($API_usergroups->request_method === 'GET') {
|
||||||
|
|
||||||
|
# GET a user group(s)
|
||||||
|
|
||||||
|
} elseif ($API_usergroups->request_method === 'POST') {
|
||||||
|
|
||||||
|
# Create a new user group
|
||||||
|
|
||||||
|
$API_usergroups->checkPermissions('admin-access-control-user-groups', 'RW');
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'user_group_name' => ['type' => 'string'],
|
||||||
|
'user_group_slugify' => ['type' => 'slugify'],
|
||||||
|
'user_group_weight' => ['type' => 'int'],
|
||||||
|
'user_group_type' => ['type' => 'enum', 'values' => ['admin', 'user']],
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_usergroups->validateData($requiredFields);
|
||||||
|
|
||||||
|
# superuser group is a fixed group name for the superuser
|
||||||
|
if ($API_usergroups->data['user_group_name'] === 'superuser' || $API_usergroups->data['user_group_slugify'] === 'superuser') {
|
||||||
|
$API_usergroups->apiOutput(400, ['error' => 'superuser group cannot be created'], 'cannot_add_superuser_group');
|
||||||
|
}
|
||||||
|
|
||||||
|
$API_usergroups->createUsergroups();
|
||||||
|
|
||||||
|
|
||||||
|
} elseif ($API_usergroups->request_method === 'PUT') {
|
||||||
|
|
||||||
|
# Update a user group
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'user_group_uuid' => ['type' => 'uuid'],
|
||||||
|
'user_group_name' => ['type' => 'string'],
|
||||||
|
'user_group_weight' => ['type' => 'int'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_usergroups->validateData($requiredFields);
|
||||||
|
|
||||||
|
$API_usergroups->updateUserGroup();
|
||||||
|
|
||||||
|
} elseif ($API_usergroups->request_method === 'DELETE') {
|
||||||
|
|
||||||
|
# Delete a user group
|
||||||
|
|
||||||
|
$API_usergroups->checkPermissions('admin-access-control-user-groups', 'RW');
|
||||||
|
|
||||||
|
# when called from the frontend will not be forwarding to a url since when its called from the frontend it doesnt need a redirection
|
||||||
|
$API_usergroups->return_url = false;
|
||||||
|
|
||||||
|
$requiredFields = ['user_group_uuid' => ['type' => 'uuid']];
|
||||||
|
|
||||||
|
$API_usergroups->validateData($requiredFields);
|
||||||
|
|
||||||
|
# Delete the device from the database.
|
||||||
|
$API_usergroups->deleteUsergroup();
|
||||||
|
}
|
||||||
116
pub/api/v1/users/apitoken/index.php
Normal file
116
pub/api/v1/users/apitoken/index.php
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_apitoken;
|
||||||
|
use api\classes\API_users;
|
||||||
|
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_apitoken.php';
|
||||||
|
|
||||||
|
$API_apitoken = new API_apitoken();
|
||||||
|
|
||||||
|
if ($API_apitoken->request_method === 'GET') {
|
||||||
|
|
||||||
|
# Retrieve all the API tokens from a user and return them.
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'user_uuid' => ['type' => 'uuid'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_apitoken->validateData($requiredFields);
|
||||||
|
|
||||||
|
if ($API_apitoken->getUserUuid() === $API_apitoken->data['user_uuid']) {
|
||||||
|
$API_apitoken->checkPermissions('user-apitoken-self', 'RW');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$API_apitoken->checkPermissions('user-apitoken-others', 'RO');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$apitokens = $API_apitoken->getTokens();
|
||||||
|
|
||||||
|
$API_apitoken->apiOutput($code = 200, ['success' => $apitokens], 'api_token_created');
|
||||||
|
|
||||||
|
} elseif ($API_apitoken->request_method === 'POST') {
|
||||||
|
|
||||||
|
# Creates a new API Token. First check if the uuid is correct and then check the permission
|
||||||
|
# After that create a new token, retrieve the newly created api_token and give a response.
|
||||||
|
$requiredFields = [
|
||||||
|
'user_uuid' => ['type' => 'uuid'],
|
||||||
|
];
|
||||||
|
$API_apitoken->validateData($requiredFields);
|
||||||
|
|
||||||
|
# First retrieve the user_uuid from the post and lookup the user
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_users.php';
|
||||||
|
|
||||||
|
$API_users = new API_users();
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'user_uuid', 1 => $API_apitoken->data['user_uuid']]]];
|
||||||
|
$user_data = $API_users->getUser()[0];
|
||||||
|
|
||||||
|
$API_apitoken->validateData($requiredFields);
|
||||||
|
|
||||||
|
if ($API_apitoken->getUserUuid() === $API_apitoken->data['user_uuid']) {
|
||||||
|
$API_apitoken->checkPermissions('user-apitoken-self', 'RW');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if ($user_data['user_email'] === 'superuser') {
|
||||||
|
$API_apitoken->apiOutput(401, ['error' => 'You are not authorized to access this resource.']);
|
||||||
|
}
|
||||||
|
$API_apitoken->checkPermissions('user-apitoken-others', 'RW');
|
||||||
|
}
|
||||||
|
|
||||||
|
$API_apitoken->createNewToken();
|
||||||
|
|
||||||
|
} elseif ($API_apitoken->request_method === 'PUT') {
|
||||||
|
|
||||||
|
# Change the revoked status of an API token
|
||||||
|
|
||||||
|
# This api call, when called from the frontend will not be forwarding to a url.
|
||||||
|
$API_apitoken->return_url = false;
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'api_token_uuid' => ['type' => 'uuid'],
|
||||||
|
'api_token_revoked' => ['type' => 'boolean'],
|
||||||
|
];
|
||||||
|
$API_apitoken->validateData($requiredFields);
|
||||||
|
$api_token_data = $API_apitoken->getToken();
|
||||||
|
|
||||||
|
if ($API_apitoken->getUserUuid() === $api_token_data['user_uuid']) {
|
||||||
|
$API_apitoken->checkPermissions('user-apitoken-self', 'RW');
|
||||||
|
} else {
|
||||||
|
if ($api_token_data['user_email'] === 'superuser') {
|
||||||
|
$API_apitoken->apiOutput(401, ['error' => 'You are not authorized to access this resource.']);
|
||||||
|
}
|
||||||
|
$API_apitoken->checkPermissions('user-apitoken-others', 'RW');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$API_apitoken->revokeToken();
|
||||||
|
|
||||||
|
} elseif ($API_apitoken->request_method === 'DELETE') {
|
||||||
|
|
||||||
|
# Deletes an API token, requies DELETE with 'api_token_uuid' first retrieve the uuid of the user with getToken then check
|
||||||
|
# if the user is another user or itself
|
||||||
|
|
||||||
|
# This api call, when called from the frontend will not be forwarding to a url.
|
||||||
|
$API_apitoken->return_url = false;
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'api_token_uuid' => ['type' => 'uuid'],
|
||||||
|
];
|
||||||
|
$API_apitoken->validateData($requiredFields);
|
||||||
|
$api_token_data = $API_apitoken->getToken();
|
||||||
|
|
||||||
|
if ($API_apitoken->getUserUuid() === $api_token_data['user_uuid']) {
|
||||||
|
$API_apitoken->checkPermissions('user-apitoken-self', 'RW');
|
||||||
|
} else {
|
||||||
|
if ($api_token_data['user_email'] === 'superuser') {
|
||||||
|
$API_apitoken->apiOutput(401, ['error' => 'You are not authorized to access this resource.']);
|
||||||
|
}
|
||||||
|
$API_apitoken->checkPermissions('user-apitoken-others', 'RW');
|
||||||
|
}
|
||||||
|
|
||||||
|
$API_apitoken->deleteToken();
|
||||||
|
|
||||||
|
}
|
||||||
41
pub/api/v1/users/avatar/index.php
Normal file
41
pub/api/v1/users/avatar/index.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
use api\classes\API_usersavatar;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_usersavatar.php';
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/imageProcessor.php';
|
||||||
|
|
||||||
|
$API_usersavatar = new API_usersavatar();
|
||||||
|
|
||||||
|
if ($API_usersavatar->request_method === 'GET') {
|
||||||
|
|
||||||
|
} elseif ($API_usersavatar->request_method === 'POST') {
|
||||||
|
# Reset a users password and send a email to the user to set a new password
|
||||||
|
|
||||||
|
$API_usersavatar->postedData['user_profile_picture'] = $API_usersavatar->createUserImage(['min_width' => 500, 'max_width' => 1000, 'min_height' => 500, 'max_height' => 1000, 'square' => true, 'allowed_types' => ['image/png'], 'max_size_kb' => 1024, 'transparent' => true]);
|
||||||
|
$API_usersavatar->postedData['user_profile_picture_thumbnail'] = $API_usersavatar->createUserImage(['min_width' => 64, 'max_width' => 64, 'min_height' => 64, 'max_height' => 64, 'square' => true, 'allowed_types' => ['image/png'], 'max_size_kb' => 1024, 'transparent' => true]);
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'user_uuid' => ['type' => 'uuid'],
|
||||||
|
'user_profile_picture' => ['type' => 'base64'],
|
||||||
|
'user_profile_picture_thumbnail' => ['type' => 'base64'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_usersavatar->validateData($requiredFields);
|
||||||
|
|
||||||
|
# if the user is different from the user logged in, check the required permissions
|
||||||
|
if ($API_usersavatar->data['user_uuid'] != $API_usersavatar->getUserUuid()) {
|
||||||
|
$API_usersavatar->checkPermissions('admin-access-admins', 'RW');
|
||||||
|
}
|
||||||
|
|
||||||
|
$API_usersavatar->updateUserImage();
|
||||||
|
|
||||||
|
$API_usersavatar->apiOutput(200, ['success' => 'Avatar was successfully changed.']);
|
||||||
|
|
||||||
|
} elseif ($API_usersavatar->request_method === 'PUT') {
|
||||||
|
|
||||||
|
} elseif ($API_usersavatar->request_method === 'DELETE') {
|
||||||
|
|
||||||
|
}
|
||||||
89
pub/api/v1/users/index.php
Normal file
89
pub/api/v1/users/index.php
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_users;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_users.php';
|
||||||
|
|
||||||
|
$API_users = new API_users();
|
||||||
|
|
||||||
|
if ($API_users->request_method === 'GET') {
|
||||||
|
#echo json_encode($api->getAllUsers());
|
||||||
|
|
||||||
|
|
||||||
|
} elseif ($API_users->request_method === 'POST') {
|
||||||
|
# create a new user
|
||||||
|
$API_users->checkPermissions('admin-access-admins', 'RW');
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'user_group_uuid' => ['type' => 'uuid'],
|
||||||
|
'user_email' => ['type' => 'email'],
|
||||||
|
'user_first_name' => ['type' => 'string'],
|
||||||
|
'user_last_name' => ['type' => 'string'],
|
||||||
|
'user_full_name' => ['type' => 'string'],
|
||||||
|
'user_phone_number' => ['type' => 'string'],
|
||||||
|
'user_status' => ['type' => 'enum', 'values' => ['active', 'inactive', 'banned', 'pending']],
|
||||||
|
'user_password' => ['type' => 'string'],
|
||||||
|
'user_pref_language' => ['type' => 'string'],
|
||||||
|
'user_password_reset_token' => ['type' => 'string'],
|
||||||
|
'user_password_reset_expires' => ['type' => 'int'],
|
||||||
|
];
|
||||||
|
|
||||||
|
# The user will need to verify their email, the password field cannot be NULL so set an random password for now till the user resets it on when verifing there email
|
||||||
|
$random_string = substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01', 64)), 0, rand(50, 64));
|
||||||
|
$user_password = password_hash($random_string, PASSWORD_BCRYPT, ["cost" => 12]);
|
||||||
|
$API_users->postedData['user_password'] = $user_password;
|
||||||
|
|
||||||
|
$API_users->postedData['user_full_name'] = trim($_POST['user_first_name'] . ' ' . $_POST['user_last_name']);
|
||||||
|
$API_users->postedData['user_pref_language'] = $_POST['user_pref_language'] ?? 'en';
|
||||||
|
|
||||||
|
# Password reset token that will be send to the newly created user
|
||||||
|
$API_users->postedData['user_password_reset_token'] = bin2hex(random_bytes(32));
|
||||||
|
$API_users->postedData['user_password_reset_expires'] = time() + 86400;
|
||||||
|
|
||||||
|
$API_users->validateData($requiredFields);
|
||||||
|
$API_users->createUser();
|
||||||
|
|
||||||
|
} elseif ($API_users->request_method === 'PUT') {
|
||||||
|
|
||||||
|
# Edit a user
|
||||||
|
$API_users->checkPermissions('admin-access-admins', 'RW');
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'user_uuid' => ['type' => 'uuid'],
|
||||||
|
'user_group_uuid' => ['type' => 'uuid'],
|
||||||
|
'user_email' => ['type' => 'email'],
|
||||||
|
'user_first_name' => ['type' => 'string'],
|
||||||
|
'user_last_name' => ['type' => 'string'],
|
||||||
|
'user_full_name' => ['type' => 'string'],
|
||||||
|
'user_phone_number' => ['type' => 'string'],
|
||||||
|
'user_status' => ['type' => 'enum', 'values' => ['active', 'inactive', 'banned', 'pending']],
|
||||||
|
'user_pref_language' => ['type' => 'string'],
|
||||||
|
'user_stompable' => ['type' => 'boolean']
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_users->postedData['user_full_name'] = trim($_POST['user_first_name'] . ' ' . $_POST['user_last_name']);
|
||||||
|
$API_users->postedData['user_pref_language'] = $_POST['user_pref_language'] ?? 'en';
|
||||||
|
$API_users->postedData['user_stompable'] = (bool)$_POST['user_stompable'];
|
||||||
|
|
||||||
|
|
||||||
|
$API_users->validateData($requiredFields);
|
||||||
|
|
||||||
|
|
||||||
|
$API_users->updateUser();
|
||||||
|
|
||||||
|
} elseif ($API_users->request_method === 'DELETE') {
|
||||||
|
|
||||||
|
|
||||||
|
$API_users->return_url = false;
|
||||||
|
|
||||||
|
$API_users->checkPermissions('admin-access-admins', 'RW');
|
||||||
|
$requiredFields = [
|
||||||
|
'user_uuid' => ['type' => 'uuid'],
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
$API_users->validateData($requiredFields);
|
||||||
|
|
||||||
|
$API_users->deleteUser();
|
||||||
|
}
|
||||||
68
pub/api/v1/users/mfa/index.php
Normal file
68
pub/api/v1/users/mfa/index.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_mfa.php';
|
||||||
|
require $_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php';
|
||||||
|
include_once $_SERVER['DOCUMENT_ROOT'] . '/login/php/authFunctions.php';
|
||||||
|
|
||||||
|
|
||||||
|
use api\classes\API_mfa;
|
||||||
|
use RobThree\Auth\TwoFactorAuth;
|
||||||
|
use RobThree\Auth\Providers\Qr\EndroidQrCodeWithLogoProvider;
|
||||||
|
|
||||||
|
$API_mfa = new API_mfa();
|
||||||
|
|
||||||
|
if ($API_mfa->request_method === 'GET') {
|
||||||
|
|
||||||
|
} elseif ($API_mfa->request_method === 'POST') {
|
||||||
|
# Setup a new MFA secret its posted from mfaSetup.php where it generated a secret
|
||||||
|
|
||||||
|
if (checkLoginAttempts() > 10) {
|
||||||
|
echo 'too many attempts, please try again later.';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# check if the secret is in the session created at the mfaSetup.php file
|
||||||
|
if (!isset($_SESSION['mfasetup']['secret'])) {
|
||||||
|
$this->apiOutput(400, ['error' => 'secret not found.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tfa = new TwoFactorAuth(new EndroidQrCodeWithLogoProvider());
|
||||||
|
|
||||||
|
$API_mfa->postedData['user_uuid'] = $_SESSION['user']['user_uuid'];
|
||||||
|
$API_mfa->postedData['user_two_factor_secret'] = $_SESSION['mfasetup']['secret'];
|
||||||
|
$API_mfa->postedData['verificationCode'] = linkVerificationPosts(); # The code is entered in six loose posts this wil link it togheter
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'user_uuid' => ['type' => 'uuid'],
|
||||||
|
'user_two_factor_secret' => ['type' => 'string'],
|
||||||
|
'verificationCode' => ['type' => 'string', 'min' => 6, 'max' => 6],
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_mfa->validateData($requiredFields);
|
||||||
|
|
||||||
|
|
||||||
|
$result = $tfa->verifyCode($API_mfa->postedData['user_two_factor_secret'], $API_mfa->postedData['verificationCode']);
|
||||||
|
if (!$result) {
|
||||||
|
addLoginAttempts();
|
||||||
|
$API_mfa->apiOutput(401, ['error' => 'Invalid verification code.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$API_mfa->enableMFA();
|
||||||
|
|
||||||
|
} elseif ($API_mfa->request_method === 'PUT') {
|
||||||
|
|
||||||
|
} elseif ($API_mfa->request_method === 'DELETE') {
|
||||||
|
|
||||||
|
# Delete a mfa code for a user
|
||||||
|
|
||||||
|
$API_mfa->return_url = false;
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'user_uuid' => ['type' => 'uuid'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_mfa->validateData($requiredFields);
|
||||||
|
|
||||||
|
$API_mfa->disableMFA();
|
||||||
|
|
||||||
|
}
|
||||||
78
pub/api/v1/users/resetpassword/index.php
Normal file
78
pub/api/v1/users/resetpassword/index.php
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_resetpassword;
|
||||||
|
use api\classes\API_users;
|
||||||
|
use bin\php\Classes\mailBuilder;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_resetpassword.php';
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/mailBuilder.php';
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_users.php';
|
||||||
|
|
||||||
|
|
||||||
|
$API_resetpassword = new API_resetpassword();
|
||||||
|
|
||||||
|
if ($API_resetpassword->request_method === 'GET') {
|
||||||
|
|
||||||
|
} elseif ($API_resetpassword->request_method === 'POST') {
|
||||||
|
# Reset a users password and send a email to the user to set a new password
|
||||||
|
|
||||||
|
$API_resetpassword->checkPermissions('admin-access-admins-resetpassword', 'RW');
|
||||||
|
|
||||||
|
# The user will need to verify their email, the password field cannot be NULL so set an random password for now till the user resets it on when verifing there email
|
||||||
|
$random_string = substr(str_shuffle(str_repeat('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01', 64)), 0, rand(50, 64));
|
||||||
|
$user_password = password_hash($random_string, PASSWORD_BCRYPT, ["cost" => 12]);
|
||||||
|
$API_resetpassword->postedData['user_password'] = $user_password;
|
||||||
|
|
||||||
|
# Password reset token that will be send to the user
|
||||||
|
$API_resetpassword->postedData['user_password_reset_token'] = bin2hex(random_bytes(32));
|
||||||
|
$API_resetpassword->postedData['user_password_reset_expires'] = time() + 86400;
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'user_uuid' => ['type' => 'uuid'],
|
||||||
|
'user_password' => ['type' => 'string'],
|
||||||
|
'user_password_reset_token' => ['type' => 'string'],
|
||||||
|
'user_password_reset_expires' => ['type' => 'int'],
|
||||||
|
];
|
||||||
|
|
||||||
|
$API_resetpassword->validateData($requiredFields);
|
||||||
|
|
||||||
|
$API_resetpassword->resetPassword();
|
||||||
|
|
||||||
|
$API_users = new API_users();
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'user_uuid', 1 => $API_resetpassword->data['user_uuid']]]];
|
||||||
|
$user_data = $API_users->getUser()[0];
|
||||||
|
|
||||||
|
# Sending an email to the user
|
||||||
|
$host = $_SERVER['HTTP_HOST'];
|
||||||
|
$verifyLink = "https://{$host}/login/verifyEmail.php?token={$API_resetpassword->data['user_password_reset_token']}";
|
||||||
|
|
||||||
|
$mail = new mailBuilder();
|
||||||
|
$mail->subject = "Hello " . $user_data['user_full_name'] . ", Here’s Your Password Reset Link";
|
||||||
|
$mail->addAddress($user_data['user_email'], $user_data['user_first_name']);
|
||||||
|
$mail->mailText = '
|
||||||
|
Hello ' . $user_data['user_first_name'] . ',<br><br>
|
||||||
|
|
||||||
|
We received a request to reset the password for your account. As a security measure, your password has been reset.<br><br>
|
||||||
|
|
||||||
|
To set a new password of your choice, click the text below:<br>
|
||||||
|
<a href="' . $verifyLink . '">Reset Password</a><br><br>
|
||||||
|
|
||||||
|
Or copy and paste the following link into your browser: <br>' . $verifyLink . '<br><br>
|
||||||
|
|
||||||
|
This link is valid for 24 hours from the time of this request.<br><br>
|
||||||
|
|
||||||
|
If you did not request this, you can safely ignore this email. No further action is required, and your account remains secure.<br><br>
|
||||||
|
|
||||||
|
Best regards,<br><br>
|
||||||
|
The Sentri gnomes
|
||||||
|
';
|
||||||
|
|
||||||
|
$mail->sendMail();
|
||||||
|
$API_resetpassword->apiOutput(200, ['success' => 'Password reset link sent successfully.']);
|
||||||
|
|
||||||
|
} elseif ($API_resetpassword->request_method === 'PUT') {
|
||||||
|
|
||||||
|
} elseif ($API_resetpassword->request_method === 'DELETE') {
|
||||||
|
|
||||||
|
}
|
||||||
100
pub/api/v1/vendors/index.php
vendored
Normal file
100
pub/api/v1/vendors/index.php
vendored
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_vendors;
|
||||||
|
use api\classes\imageProcessor;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_vendors.php';
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/imageProcessor.php';
|
||||||
|
|
||||||
|
$API_vendors = new API_vendors();
|
||||||
|
|
||||||
|
if ($API_vendors->request_method === 'GET') {
|
||||||
|
|
||||||
|
# get all the vendor
|
||||||
|
|
||||||
|
$API_vendors->checkPermissions('admin-vendors', 'RO');
|
||||||
|
|
||||||
|
} elseif ($API_vendors->request_method === 'POST') {
|
||||||
|
|
||||||
|
# create a new vendor
|
||||||
|
|
||||||
|
$API_vendors->checkPermissions('admin-vendors', 'RW');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$imageProcessor = new imageProcessor('vendor_image');
|
||||||
|
$imageProcessor->imageRestrictions = [
|
||||||
|
'min_width' => 200,
|
||||||
|
'max_width' => 200,
|
||||||
|
'min_height' => 200,
|
||||||
|
'max_height' => 200,
|
||||||
|
'square' => true,
|
||||||
|
'allowed_types' => ['image/png'],
|
||||||
|
'max_size_kb' => 1024
|
||||||
|
];
|
||||||
|
$imageProcessor->validateAndProcess();
|
||||||
|
$finalImageData = $imageProcessor->returnBase64image();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$API_vendors->apiOutput(401, ['error' => 'Error: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$API_vendors->postedData['vendor_image'] = $finalImageData;
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'vendor_name' => ['type' => 'string'],
|
||||||
|
'vendor_slugify' => ['type' => 'slugify'],
|
||||||
|
'vendor_enabled' => ['type' => 'boolean'],
|
||||||
|
'vendor_description' => ['type' => 'string'],
|
||||||
|
];
|
||||||
|
$optionalFields = ['vendor_image' => ['type' => 'string']];
|
||||||
|
|
||||||
|
$API_vendors->validateData($requiredFields, $optionalFields);
|
||||||
|
|
||||||
|
$API_vendors->createVendor();
|
||||||
|
|
||||||
|
} elseif ($API_vendors->request_method === 'PUT') {
|
||||||
|
|
||||||
|
# edit a vendor
|
||||||
|
|
||||||
|
$API_vendors->checkPermissions('admin-vendors', 'RW');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$imageProcessor = new imageProcessor('vendor_image');
|
||||||
|
$imageProcessor->imageRestrictions = [
|
||||||
|
'min_width' => 200,
|
||||||
|
'max_width' => 200,
|
||||||
|
'min_height' => 200,
|
||||||
|
'max_height' => 200,
|
||||||
|
'square' => true,
|
||||||
|
'allowed_types' => ['image/png'],
|
||||||
|
'max_size_kb' => 1024
|
||||||
|
];
|
||||||
|
$imageProcessor->validateAndProcess();
|
||||||
|
$finalImageData = $imageProcessor->returnBase64image();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$API_vendors->apiOutput(401, ['error' => 'Error: ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($finalImageData) {
|
||||||
|
$API_vendors->postedData['vendor_image'] = $finalImageData;
|
||||||
|
}
|
||||||
|
|
||||||
|
$requiredFields = [
|
||||||
|
'vendor_name' => ['type' => 'string'],
|
||||||
|
'vendor_uuid' => ['type' => 'slugify'],
|
||||||
|
'vendor_enabled' => ['type' => 'boolean'],
|
||||||
|
'vendor_description' => ['type' => 'string'],
|
||||||
|
];
|
||||||
|
$optionalFields = ['vendor_image' => ['type' => 'string']];
|
||||||
|
|
||||||
|
$API_vendors->validateData($requiredFields, $optionalFields);
|
||||||
|
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'vendor_uuid', 1 => $API_vendors->data['vendor_uuid']]]];
|
||||||
|
$API_vendors->getVendors();
|
||||||
|
|
||||||
|
$API_vendors->editVendor();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
290
pub/bin/locales/en.php
Normal file
290
pub/bin/locales/en.php
Normal file
@@ -0,0 +1,290 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'active_language' => 'English',
|
||||||
|
'nl' => 'Dutch',
|
||||||
|
'en' => 'English',
|
||||||
|
'version' => 'Version',
|
||||||
|
'hi' => 'Hi',
|
||||||
|
'change_password' => 'Change password',
|
||||||
|
'feedback' => 'Feedback',
|
||||||
|
'changelog' => 'Changelog',
|
||||||
|
'logout' => 'Logout',
|
||||||
|
'dashboard' => 'Dashboard',
|
||||||
|
'platforms' => 'Platforms',
|
||||||
|
'vendors' => 'Vendors',
|
||||||
|
'devices' => 'Devices',
|
||||||
|
'device_settings' => 'Settings',
|
||||||
|
'organizations' => 'Organizations',
|
||||||
|
'tenants' => 'Tenants',
|
||||||
|
'users' => 'Users',
|
||||||
|
'user' => 'User',
|
||||||
|
'phones' => 'Phones',
|
||||||
|
'phonebook' => 'Phonebook',
|
||||||
|
'phonebooks' => 'Phonebooks',
|
||||||
|
'provisioning' => 'Provisioning',
|
||||||
|
'activity' => 'Activity',
|
||||||
|
'inventory' => 'Inventory',
|
||||||
|
'customers' => 'Customers',
|
||||||
|
'rps_panel' => 'RPS Panel',
|
||||||
|
'admin_settings' => 'Admin Settings',
|
||||||
|
'portal_settings' => 'Portal Settings',
|
||||||
|
'dashboard_text_platforms' => 'Manage VoIP platforms.',
|
||||||
|
'dashboard_text_vendors' => 'Manage VoIP vendors.',
|
||||||
|
'dashboard_text_devices' => 'Manage VoIP devices and modules.',
|
||||||
|
'dashboard_text_device_settings' => 'Manage settings for devices and modules.',
|
||||||
|
'dashboard_text_organizations' => 'Manage available customers.',
|
||||||
|
'dashboard_text_phones' => 'Edit phone configurations.',
|
||||||
|
'dashboard_text_phonebooks' => 'Edit phonebooks and contacts.',
|
||||||
|
'admin_management' => 'Admin Access',
|
||||||
|
'access_control' => 'Access Control',
|
||||||
|
'monitoring' => 'Monitoring',
|
||||||
|
'systemconfig' => 'Portal Management',
|
||||||
|
'dashboard_text_admin_management' => 'Manage access for administrators',
|
||||||
|
'dashboard_text_access_control' => 'Edit permission and groups',
|
||||||
|
'dashboard_text_monitoring' => 'Monitoring and logs from the portal',
|
||||||
|
'dashboard_text_systemconfig' => 'System configuration management',
|
||||||
|
'language' => 'Change language',
|
||||||
|
'changed_language' => 'Language changed',
|
||||||
|
'add_platform' => 'Add platform',
|
||||||
|
'edit_platform' => 'Edit platform',
|
||||||
|
'edited_platform' => 'Edited platform',
|
||||||
|
'uuid' => 'uuid',
|
||||||
|
'platform_name' => 'Name',
|
||||||
|
'platform_slugify' => 'Slugify',
|
||||||
|
'platform_enabled' => 'Enabled',
|
||||||
|
'platform_image' => 'Image',
|
||||||
|
'upload_image' => 'Upload a Image',
|
||||||
|
'platform_description' => 'Description',
|
||||||
|
'close' => 'Close',
|
||||||
|
'enabled' => 'Enabled',
|
||||||
|
'enable' => 'Enable',
|
||||||
|
'disabled' => 'Disabled',
|
||||||
|
'platform_added' => 'Platform successfully added',
|
||||||
|
'error_contact_support' => 'Something went wrong, please contact support.',
|
||||||
|
'error_no_valid_json' => 'Invalid JSON format',
|
||||||
|
'edit' => 'Edit',
|
||||||
|
'info' => 'Info',
|
||||||
|
'delete' => 'Delete',
|
||||||
|
'information' => 'Information',
|
||||||
|
'create_date' => 'Create date',
|
||||||
|
'date' => 'Date',
|
||||||
|
'time' => 'Time',
|
||||||
|
'last_modified_date' => 'Last modified date',
|
||||||
|
'last_update' => 'Last update',
|
||||||
|
'never' => 'Never',
|
||||||
|
'save' => 'Save',
|
||||||
|
'add_vendor' => 'Add vendor',
|
||||||
|
'edit_vendor' => 'Edit vendor',
|
||||||
|
'edited_vendor' => 'Edited vendor',
|
||||||
|
'vendor_name' => 'Name',
|
||||||
|
'vendor_enabled' => 'Enabled',
|
||||||
|
'vendor_slugify' => 'Slugify',
|
||||||
|
'vendor_description' => 'Description',
|
||||||
|
'vendor_image' => 'Image',
|
||||||
|
'vendor_uuid' => 'uuid',
|
||||||
|
'vendor_added' => 'Vendor added successfully',
|
||||||
|
'add_device' => 'Add device',
|
||||||
|
'device_vendor' => 'Vendor',
|
||||||
|
'device_name' => 'Name',
|
||||||
|
'device_slugify' => 'Slugify',
|
||||||
|
'device_notes' => 'Notes',
|
||||||
|
'device_image' => 'Image',
|
||||||
|
'device_uuid' => 'uuid',
|
||||||
|
'device_added' => 'Device added successfully',
|
||||||
|
'device_enabled' => 'Enabled',
|
||||||
|
'device_max_accounts' => 'Max. SIP accounts',
|
||||||
|
'device_allowed_codecs' => 'Allowed codecs',
|
||||||
|
'device_extensions' => 'Extensions',
|
||||||
|
'device_extra' => 'Extra data',
|
||||||
|
'json_enter' => 'Enter JSON data',
|
||||||
|
'json_valid' => 'JSON valid',
|
||||||
|
'json_invalid' => 'Invalid JSON. Please check your input.',
|
||||||
|
'add_phone_device' => 'Add phone',
|
||||||
|
'add_module_device' => 'Add module',
|
||||||
|
'add_handset_device' => 'Add handset',
|
||||||
|
'add_base_device' => 'Add base station',
|
||||||
|
'no_vendor_found' => 'No vendors found',
|
||||||
|
'image_no_equal_dimensions' => 'The uploaded image must have equal width and height.',
|
||||||
|
'image_size_exceeded_500' => 'The uploaded image must not exceed 500x500 pixels.',
|
||||||
|
'image_not_png' => 'The uploaded image is not a PNG.',
|
||||||
|
'edit_device' => 'Edit device',
|
||||||
|
'edited_device' => 'Device edited successfully',
|
||||||
|
'search_' => 'Search...',
|
||||||
|
'no_device_found' => 'No devices found',
|
||||||
|
'action_confirm' => 'Are you sure?',
|
||||||
|
'action_confirm_text' => 'Are you sure you want to perform this action?',
|
||||||
|
'action_confirm_button' => 'Yes!',
|
||||||
|
'action_cancel_button' => 'Nope!',
|
||||||
|
'action_success_text' => 'Action successfully performed!',
|
||||||
|
'action_success_title' => 'Done!',
|
||||||
|
'action_error_text' => 'An error occurred :(',
|
||||||
|
'action_error_title' => 'Error!',
|
||||||
|
'action_cancel_confirm_title' => 'Cancelled!',
|
||||||
|
'action_cancel_confirm_text' => 'Nothing done, you are safe!',
|
||||||
|
'yes' => 'Yes',
|
||||||
|
'no' => 'No',
|
||||||
|
'view' => 'View',
|
||||||
|
'drag_and_drop_files_here' => 'Drag and Drop files here',
|
||||||
|
'filename' => 'Filename',
|
||||||
|
'filesize' => 'File size',
|
||||||
|
'file_last_modified' => 'Last modified',
|
||||||
|
'document' => 'Document',
|
||||||
|
'extensions_available' => 'Extensions available',
|
||||||
|
'handsets_available' => 'Extensions available',
|
||||||
|
'no_extensions_available' => 'No extensions available',
|
||||||
|
'parent_device' => 'Associated Devices',
|
||||||
|
'templates' => 'Templates',
|
||||||
|
'default' => 'Default',
|
||||||
|
'template_added' => 'Template added successfully',
|
||||||
|
'eol' => 'End of Life',
|
||||||
|
'user_groups' => 'User groups',
|
||||||
|
'user_group' => 'User group',
|
||||||
|
'add_user_groups' => 'Add user group',
|
||||||
|
'user_group_name' => 'Group name',
|
||||||
|
'user_group_slugify' => 'Slugify name',
|
||||||
|
'no_user_groups_found' => 'No user groups found',
|
||||||
|
'actions' => 'Actions',
|
||||||
|
'weight' => 'weigth',
|
||||||
|
'edit_user_groups' => 'Edit Group',
|
||||||
|
'global_settings' => 'Global',
|
||||||
|
'permission' => 'Permissions',
|
||||||
|
'administrators' => 'Admins',
|
||||||
|
'admin' => 'Administrator',
|
||||||
|
'portal_name' => 'Portal name',
|
||||||
|
'portal_slugify' => 'Portal slugify',
|
||||||
|
'portal_provider_name' => 'Portal provider name',
|
||||||
|
'portal_provider_slugify' => 'Portal provider slugify',
|
||||||
|
'admin_auth_methods' => 'Admin authentication methods',
|
||||||
|
'cacert_url' => 'CA certificate URL',
|
||||||
|
'autop_url' => 'Autoprovisioning URL',
|
||||||
|
'copied' => 'Copied!',
|
||||||
|
'copy_text_success' => 'The text is copied!',
|
||||||
|
'ok' => 'Okay',
|
||||||
|
'user_group_type' => 'Group type',
|
||||||
|
'add_admin' => 'Add admin',
|
||||||
|
'user_added' => 'User successfully added',
|
||||||
|
'user_already_exsist' => 'There already is an user with this email address',
|
||||||
|
'user_email' => 'Email',
|
||||||
|
'first_name' => 'First name',
|
||||||
|
'last_name' => 'Last name',
|
||||||
|
'full_name' => 'Name',
|
||||||
|
'password' => 'Password',
|
||||||
|
'phone_number' => 'Phone number',
|
||||||
|
'user_status' => 'Status',
|
||||||
|
'preferred_language' => 'Language',
|
||||||
|
'portal_management' => 'Portal management',
|
||||||
|
'overview' => 'Overview',
|
||||||
|
'mfa' => 'MFA',
|
||||||
|
'ldap_settings' => 'LDAP',
|
||||||
|
'saml_settings' => 'SAML',
|
||||||
|
'health_check' => 'Health Check',
|
||||||
|
'cannot_add_superuser_group' => 'Superuser group cannot be modified',
|
||||||
|
'on' => 'On',
|
||||||
|
'off' => 'Off',
|
||||||
|
'edit_admin' => 'Edit admin',
|
||||||
|
'add_permission' => 'Add permission',
|
||||||
|
'edit_permission' => 'Edit permission',
|
||||||
|
'permission_name' => 'Permission name',
|
||||||
|
'permission_slugify' => 'Permission slugify',
|
||||||
|
'item_already_exists' => 'Item with this name already exists',
|
||||||
|
'item_added' => 'Item successfully added',
|
||||||
|
'group_added' => 'Group successfully added',
|
||||||
|
'permission_description' => 'Permission description',
|
||||||
|
'unable_to_find_item' => 'Item not found',
|
||||||
|
'NA' => 'Not Available',
|
||||||
|
'RO' => 'Read Only',
|
||||||
|
'RW' => 'Read Write',
|
||||||
|
'user_profile' => 'Profile',
|
||||||
|
'set_mfa' => 'Enable two factor authentication',
|
||||||
|
'reset_mfa' => 'Disable two factor authentication',
|
||||||
|
'avatar_changed' => 'Avatar changed',
|
||||||
|
'mail_settings' => 'Mail',
|
||||||
|
'mail_smtp_host' => 'SMTP host',
|
||||||
|
'mail_smtp_auth' => 'SMTP Authentication',
|
||||||
|
'mail_smtp_port' => 'SMTP Port',
|
||||||
|
'mail_smtp_user' => 'SMTP Username',
|
||||||
|
'mail_smtp_pass' => 'SMTP Password',
|
||||||
|
'mail_smtp_secure' => 'SMTP Secure',
|
||||||
|
'mail_from_address' => 'From Address',
|
||||||
|
'mail_from_name' => 'From Name',
|
||||||
|
'mail_settings_edited' => 'Mail settings saved',
|
||||||
|
'admin_creation_instruction' => 'After creating an admin user, an email will be sent to them to verify their email address and create a password.',
|
||||||
|
'edit_profile' => 'Edit profile',
|
||||||
|
'user_saved' => 'Profile updated',
|
||||||
|
'insecure_password' => 'Insecure Password',
|
||||||
|
'user_management' => 'User management',
|
||||||
|
'reset_password' => 'Reset password',
|
||||||
|
'mfa_disabled' => 'Two factor authentication is disabled.',
|
||||||
|
'send_password_reset' => 'Send password reset email',
|
||||||
|
'email_send' => 'Email sent',
|
||||||
|
'api_token_created' => 'API token created',
|
||||||
|
'permission_created' => 'Permission created',
|
||||||
|
'permission_updated' => 'Permission updated',
|
||||||
|
'modules' => 'Modules',
|
||||||
|
'module' => 'Module',
|
||||||
|
'autoproviosioning' => 'Autoprovisioning',
|
||||||
|
'dashboard_text_stompjes' => 'Can you kick it?',
|
||||||
|
'office' => 'Office',
|
||||||
|
'stompjeslist' => 'Stompjeslist',
|
||||||
|
'stompable' => 'Stompable',
|
||||||
|
'stompjes' => 'Stomps',
|
||||||
|
'stomped' => 'Stomped',
|
||||||
|
'stomped_success' => 'Ough and other oof sounds',
|
||||||
|
'deleted' => 'Deleted',
|
||||||
|
'from' => 'From',
|
||||||
|
'to' => 'To',
|
||||||
|
'sources' => 'Sources',
|
||||||
|
'api_token' => 'API token',
|
||||||
|
'api_tokens' => 'API tokens',
|
||||||
|
'api_token_copy_new' => 'This token is visible only once. Make sure to copy and save it now if you plan to use it later.',
|
||||||
|
'generate_new_api_token' => 'Generate new API token',
|
||||||
|
'inserve_url' => 'Inserve URL',
|
||||||
|
'inserve_source' => 'Inserve Configuration',
|
||||||
|
'test_connection' => 'Test Connection',
|
||||||
|
'connection_success_title' => 'Successful',
|
||||||
|
'connection_success_text' => 'Connection made successful',
|
||||||
|
'connection_error_title' => 'Error',
|
||||||
|
'connection_error_text' => 'Connection error',
|
||||||
|
'companies' => 'Companies',
|
||||||
|
'sync' => 'Sync',
|
||||||
|
'company_activated_title' => 'Activated',
|
||||||
|
'company_deactivated_title' => 'Deactivated',
|
||||||
|
'company_activated_text' => 'Company is now activated.',
|
||||||
|
'company_deactivated_text' => 'Company is now deactivated.',
|
||||||
|
'company_name' => 'Name',
|
||||||
|
'company' => 'Company',
|
||||||
|
'company_id' => 'ID',
|
||||||
|
'company_debtor' => 'Debtor',
|
||||||
|
'company_state' => 'State',
|
||||||
|
'server_count' => 'Server count',
|
||||||
|
'show_all' => 'Show all',
|
||||||
|
'show_active' => 'Show active',
|
||||||
|
'servers' => 'Servers',
|
||||||
|
'server_overview' => 'Server overview',
|
||||||
|
'dashboard_text_server_overview' => 'View the servers overview',
|
||||||
|
'server_hostname' => 'Hostname',
|
||||||
|
'server_power_state' => 'On/Off',
|
||||||
|
'server_state' => 'State',
|
||||||
|
'server_os' => 'OS',
|
||||||
|
'server_cpu' => 'CPU',
|
||||||
|
'server_memory' => 'Mem',
|
||||||
|
'server_memory_demand' => 'Mem dmnd.',
|
||||||
|
'server_disks' => 'Disks',
|
||||||
|
'server_ipv4' => 'IPv4',
|
||||||
|
'server_ipv6' => 'IPv6',
|
||||||
|
'server_vm_snapshot' => 'Snapshot',
|
||||||
|
'server_vm_generation' => 'Gen',
|
||||||
|
'server_licenses' => 'Licenses',
|
||||||
|
'server_backup' => 'Backups',
|
||||||
|
'disk_space' => 'Disk space',
|
||||||
|
'disk_used' => 'Disk used',
|
||||||
|
'disk_location' => 'Disk location',
|
||||||
|
'type' => 'Type',
|
||||||
|
'all_technical_information' => 'All technical information',
|
||||||
|
'avatar' => 'Avatar',
|
||||||
|
'user_state' => 'Staat',
|
||||||
|
'last_login' => 'Last login',
|
||||||
|
'description' => 'Description',
|
||||||
|
'name' => 'Name',
|
||||||
|
'show_del' => 'del.'
|
||||||
|
];
|
||||||
290
pub/bin/locales/nl.php
Normal file
290
pub/bin/locales/nl.php
Normal file
@@ -0,0 +1,290 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'active_language' => 'Nederlands',
|
||||||
|
'nl' => 'Nederlands',
|
||||||
|
'en' => 'Engels',
|
||||||
|
'version' => 'Versie',
|
||||||
|
'hi' => 'Hoi',
|
||||||
|
'change_password' => 'Wachtwoord wijzigen',
|
||||||
|
'feedback' => 'Feedback',
|
||||||
|
'changelog' => 'Changelog',
|
||||||
|
'logout' => 'Uitloggen',
|
||||||
|
'dashboard' => 'Dashboard',
|
||||||
|
'platforms' => 'Platformen',
|
||||||
|
'vendors' => 'Vendors',
|
||||||
|
'devices' => 'Apparaten',
|
||||||
|
'device_settings' => 'Instellingen',
|
||||||
|
'organizations' => 'Organisaties',
|
||||||
|
'tenants' => 'Organisaties',
|
||||||
|
'users' => 'Gebruikers',
|
||||||
|
'user' => 'Gebruiker',
|
||||||
|
'phones' => 'Telefoons',
|
||||||
|
'phonebook' => 'Telefoonboek',
|
||||||
|
'phonebooks' => 'Telefoonboeken',
|
||||||
|
'provisioning' => 'Provisioning',
|
||||||
|
'activity' => 'Activiteit',
|
||||||
|
'inventory' => 'Inventaris',
|
||||||
|
'customers' => 'Klanten',
|
||||||
|
'rps_panel' => 'RPS Paneel',
|
||||||
|
'admin_settings' => 'Beheer Instellingen',
|
||||||
|
'portal_settings' => 'Portaal Settings',
|
||||||
|
'dashboard_text_platforms' => 'Beheer VoIP-platformen.',
|
||||||
|
'dashboard_text_vendors' => 'Beheer VoIP-vendors.',
|
||||||
|
'dashboard_text_devices' => 'Beheer VoIP-apparaten en modules.',
|
||||||
|
'dashboard_text_device_settings' => 'Beheer instellingen voor apparaten en modules.',
|
||||||
|
'dashboard_text_organizations' => 'Beheer beschikbare klanten.',
|
||||||
|
'dashboard_text_phones' => 'Bewerk telefoonconfiguraties.',
|
||||||
|
'dashboard_text_phonebooks' => 'Bewerk telefoonboeken en contacten.',
|
||||||
|
'admin_management' => 'Admin Beheer',
|
||||||
|
'access_control' => 'Toegangs beheer',
|
||||||
|
'monitoring' => 'Monitoring',
|
||||||
|
'systemconfig' => 'Portaal beheer',
|
||||||
|
'dashboard_text_admin_management' => 'Toegang beheer voor administrators',
|
||||||
|
'dashboard_text_access_control' => 'Beheer permissies en groepen',
|
||||||
|
'dashboard_text_monitoring' => 'Monitoring van systeem en gebeurtenissen',
|
||||||
|
'dashboard_text_systemconfig' => 'Systeem configuratie',
|
||||||
|
'language' => 'Taal aanpassen',
|
||||||
|
'changed_language' => 'Taal aangepast',
|
||||||
|
'add_platform' => 'Platform toevoegen',
|
||||||
|
'edit_platform' => 'Platform bewerken',
|
||||||
|
'edited_platform' => 'Platform bewerkt',
|
||||||
|
'uuid' => 'Platform uuid',
|
||||||
|
'platform_name' => 'Naam',
|
||||||
|
'platform_slugify' => 'Slugify',
|
||||||
|
'platform_enabled' => 'Ingeschakeld',
|
||||||
|
'platform_image' => 'Afbeelding',
|
||||||
|
'upload_image' => 'Upload een afbeelding',
|
||||||
|
'platform_description' => 'Beschrijving',
|
||||||
|
'close' => 'Sluiten',
|
||||||
|
'enabled' => 'Ingeschakeld',
|
||||||
|
'enable' => 'Inschakelen',
|
||||||
|
'disabled' => 'Uitgeschakeld',
|
||||||
|
'platform_added' => 'Platform succesvol toegevoegd.',
|
||||||
|
'error_contact_support' => 'Er ging iets fout, neem contact op met support.',
|
||||||
|
'error_no_valid_json' => 'Geen geldige JSON ontvangen',
|
||||||
|
'edit' => 'Bewerken',
|
||||||
|
'info' => 'Info',
|
||||||
|
'delete' => 'Verwijder',
|
||||||
|
'information' => 'Informatie',
|
||||||
|
'create_date' => 'Creatie datum',
|
||||||
|
'date' => 'Datum',
|
||||||
|
'time' => 'Tijd',
|
||||||
|
'last_modified_date' => 'Laatst gewijzigd datum',
|
||||||
|
'last_update' => 'Laatste update',
|
||||||
|
'never' => 'Nooit',
|
||||||
|
'save' => 'Opslaan',
|
||||||
|
'add_vendor' => 'Vendor toevoegen',
|
||||||
|
'edit_vendor' => 'Vendor bewerken',
|
||||||
|
'edited_vendor' => 'Vendor bewerkt',
|
||||||
|
'vendor_name' => 'Naam',
|
||||||
|
'vendor_enabled' => 'Ingeschakeld',
|
||||||
|
'vendor_slugify' => 'Slugify',
|
||||||
|
'vendor_description' => 'Beschrijving',
|
||||||
|
'vendor_image' => 'Afbeelding',
|
||||||
|
'vendor_uuid' => 'uuid',
|
||||||
|
'vendor_added' => 'Vendor succesvol toegevoegd.',
|
||||||
|
'add_device' => 'Device toevoegen',
|
||||||
|
'device_vendor' => 'Vendor',
|
||||||
|
'device_name' => 'Naam',
|
||||||
|
'device_slugify' => 'Slugify',
|
||||||
|
'device_notes' => 'Notities',
|
||||||
|
'device_image' => 'Afbeelding',
|
||||||
|
'device_uuid' => 'uuid',
|
||||||
|
'device_added' => 'Device succesvol toegevoegd.',
|
||||||
|
'device_enabled' => 'Ingeschakeld',
|
||||||
|
'device_max_accounts' => 'Max. SIP accounts',
|
||||||
|
'device_allowed_codecs' => 'Toegestane codecs',
|
||||||
|
'device_extensions' => 'Extensies',
|
||||||
|
'device_extra' => 'Extra data',
|
||||||
|
'json_enter' => 'Voer JSON data in',
|
||||||
|
'json_valid' => 'JSON geldig',
|
||||||
|
'json_invalid' => 'JSON ongeldig. Kijk of de input klopt',
|
||||||
|
'add_phone_device' => 'Telefoon toevoegen',
|
||||||
|
'add_module_device' => 'Module toevoegen',
|
||||||
|
'add_handset_device' => 'Handset toevoegen',
|
||||||
|
'add_base_device' => 'Base station toevoegen',
|
||||||
|
'no_vendor_found' => 'Geen vendors gevonden',
|
||||||
|
'image_no_equal_dimensions' => 'De afbeelding moet dezelfde hoogte en breedte hebben',
|
||||||
|
'image_size_exceeded_500' => 'De afbeelding mag niet groter dan 500x500 pixels zijn',
|
||||||
|
'image_not_png' => 'De afbeelding is geen png bestand',
|
||||||
|
'edit_device' => 'Device bewerken',
|
||||||
|
'edited_device' => 'Device bewerkt.',
|
||||||
|
'search_' => 'Zoeken...',
|
||||||
|
'no_device_found' => 'Geen device gevonden',
|
||||||
|
'action_confirm' => 'Weet je het zeker?',
|
||||||
|
'action_confirm_text' => 'Weet je zeker dat je deze actie wilt uitvoeren?',
|
||||||
|
'action_confirm_button' => 'Ja!',
|
||||||
|
'action_cancel_button' => 'Nope!',
|
||||||
|
'action_success_text' => 'Actie succesvol uitgevoerd!',
|
||||||
|
'action_success_title' => 'Klaar!',
|
||||||
|
'action_error_text' => 'Er ging iets mis :(',
|
||||||
|
'action_error_title' => 'Error!',
|
||||||
|
'action_cancel_confirm_title' => 'Geannuleerd!',
|
||||||
|
'action_cancel_confirm_text' => 'Niks gedaan, je bent veilig!',
|
||||||
|
'yes' => 'Ja',
|
||||||
|
'no' => 'Nee',
|
||||||
|
'view' => 'Bekijken',
|
||||||
|
'drag_and_drop_files_here' => 'Sleep en zet bestanden hier neer',
|
||||||
|
'filename' => 'bestandsnaam',
|
||||||
|
'filesize' => 'bestandsgrootte',
|
||||||
|
'file_last_modified' => 'Gewijzigd',
|
||||||
|
'document' => 'Document',
|
||||||
|
'extensions_available' => 'Extensies beschikbaar',
|
||||||
|
'handsets_available' => 'Handsets beschikbaar',
|
||||||
|
'no_extensions_available' => 'Geen extensies beschikbaar',
|
||||||
|
'parent_device' => 'Verbonden Apparaten',
|
||||||
|
'templates' => 'Templates',
|
||||||
|
'default' => 'Standaard',
|
||||||
|
'template_added' => 'Template succesvol toegevoegd',
|
||||||
|
'eol' => 'End of Life',
|
||||||
|
'user_groups' => 'Gebruikers groepen',
|
||||||
|
'user_group' => 'Gebruikers groep',
|
||||||
|
'add_user_groups' => 'Groep toevoegen',
|
||||||
|
'user_group_name' => 'Groep naam',
|
||||||
|
'user_group_slugify' => 'Slugify naam',
|
||||||
|
'no_user_groups_found' => 'Geen groepen gevonden',
|
||||||
|
'actions' => 'Acties',
|
||||||
|
'weight' => 'weigth',
|
||||||
|
'edit_user_groups' => 'Groep bewerken',
|
||||||
|
'global_settings' => 'Globaal',
|
||||||
|
'permission' => 'Permissies',
|
||||||
|
'administrators' => 'Admins',
|
||||||
|
'admin' => 'Administrator',
|
||||||
|
'portal_name' => 'Portaal naam',
|
||||||
|
'portal_slugify' => 'Portaal slugify',
|
||||||
|
'portal_provider_name' => 'Portaal provider naam',
|
||||||
|
'portal_provider_slugify' => 'Portaal provider slugify',
|
||||||
|
'admin_auth_methods' => 'Admin authenticatie methodes',
|
||||||
|
'cacert_url' => 'CA certificate URL',
|
||||||
|
'autop_url' => 'Autoprovisioning URL',
|
||||||
|
'copied' => 'Gekopieerd!',
|
||||||
|
'copy_text_success' => 'De text is gekopieerd!',
|
||||||
|
'ok' => 'Leuk',
|
||||||
|
'user_group_type' => 'Groep type',
|
||||||
|
'add_admin' => 'Admin toevoegen',
|
||||||
|
'user_added' => 'Gebruiker succesvol toegevoegd',
|
||||||
|
'user_already_exsist' => 'Er bestaat al een gebruiker met dit email adres',
|
||||||
|
'user_email' => 'Email',
|
||||||
|
'first_name' => 'Voornaam',
|
||||||
|
'last_name' => 'Achternaam',
|
||||||
|
'full_name' => 'Naam',
|
||||||
|
'password' => 'Wachtwoord',
|
||||||
|
'phone_number' => 'Telefoonnummer',
|
||||||
|
'user_status' => 'Status',
|
||||||
|
'preferred_language' => 'Taal',
|
||||||
|
'portal_management' => 'Portaal beheer',
|
||||||
|
'overview' => 'Overzicht',
|
||||||
|
'mfa' => 'MFA',
|
||||||
|
'ldap_settings' => 'LDAP',
|
||||||
|
'saml_settings' => 'SAML',
|
||||||
|
'health_check' => 'Health Check',
|
||||||
|
'cannot_add_superuser_group' => 'Superuser groep kan niet gewijzigd worden',
|
||||||
|
'on' => 'Aan',
|
||||||
|
'off' => 'Uit',
|
||||||
|
'edit_admin' => 'Admin bewerken',
|
||||||
|
'add_permission' => 'Permissie toevoegen',
|
||||||
|
'edit_permission' => 'Permissie bewerken',
|
||||||
|
'permission_name' => 'Permissie naam',
|
||||||
|
'permission_slugify' => 'Permissie slugify',
|
||||||
|
'item_already_exists' => 'Item met deze informatie wordt al gebruikt',
|
||||||
|
'item_added' => 'Item succesvol toegevoegd',
|
||||||
|
'group_added' => 'Groep succesvol toegevoegd',
|
||||||
|
'permission_description' => 'Permissie beschrijving',
|
||||||
|
'unable_to_find_item' => 'Item niet gevonden',
|
||||||
|
'NA' => 'Not Available',
|
||||||
|
'RO' => 'Read Only',
|
||||||
|
'RW' => 'Read Write',
|
||||||
|
'user_profile' => 'Profiel',
|
||||||
|
'set_mfa' => 'Two factor authenticatie instellen',
|
||||||
|
'reset_mfa' => 'Two factor authenticatie uitschakelen',
|
||||||
|
'avatar_changed' => 'Avatar gewijzigd',
|
||||||
|
'mail_settings' => 'Mail',
|
||||||
|
'mail_smtp_host' => 'SMTP host',
|
||||||
|
'mail_smtp_auth' => 'SMTP Authenticatie',
|
||||||
|
'mail_smtp_port' => 'SMTP Poort',
|
||||||
|
'mail_smtp_user' => 'SMTP Gebruiker',
|
||||||
|
'mail_smtp_pass' => 'SMTP Wachtwoord',
|
||||||
|
'mail_smtp_secure' => 'SMTP Secure',
|
||||||
|
'mail_from_address' => 'Van Adres',
|
||||||
|
'mail_from_name' => 'Van Naam',
|
||||||
|
'mail_settings_edited' => 'Mail instellingen aangepast',
|
||||||
|
'admin_creation_instruction' => 'Na het aanmaken van een beheerder ontvangt deze een e-mail om het e-mailadres te verifiëren en een wachtwoord aan te maken.',
|
||||||
|
'edit_profile' => 'Profiel bewerken',
|
||||||
|
'user_saved' => 'Profiel opgeslagen',
|
||||||
|
'insecure_password' => 'Onveilig wachtwoord',
|
||||||
|
'user_management' => 'Gebruiker management',
|
||||||
|
'reset_password' => 'Wachtwoord wijzigen',
|
||||||
|
'mfa_disabled' => 'Two factor authenticatie is uitgeschakeld',
|
||||||
|
'send_password_reset' => 'Wachtwoord herstel e-mail versturen',
|
||||||
|
'email_send' => 'Verstuur e-mail',
|
||||||
|
'api_token_created' => 'API token toegevoegd',
|
||||||
|
'permission_created' => 'Permission aangemaakt',
|
||||||
|
'permission_updated' => 'Permission bijgewerkt',
|
||||||
|
'modules' => 'Modules',
|
||||||
|
'module' => 'Module',
|
||||||
|
'autoproviosioning' => 'Autoprovisioning',
|
||||||
|
'dashboard_text_stompjes' => 'Kan je stompen?',
|
||||||
|
'office' => 'Kantoor',
|
||||||
|
'stompjeslist' => 'Stompjeslijst',
|
||||||
|
'stompable' => 'Stompabel',
|
||||||
|
'stompjes' => 'Stompjes',
|
||||||
|
'stomped' => 'Gestompt',
|
||||||
|
'stomped_success' => 'Absoluut grof stomp geweld, lekker!',
|
||||||
|
'deleted' => 'Verwijderd',
|
||||||
|
'from' => 'Van',
|
||||||
|
'to' => 'tot',
|
||||||
|
'sources' => 'Bronnen',
|
||||||
|
'api_token' => 'API token',
|
||||||
|
'api_tokens' => 'API tokens',
|
||||||
|
'api_token_copy_new' => 'Deze token is alleen nu zichtbaar, kopieer hem nu als je hem later wilt gebruiken.',
|
||||||
|
'generate_new_api_token' => 'Genereer API token',
|
||||||
|
'inserve_url' => 'Inserve URL',
|
||||||
|
'inserve_source' => 'Inserve Configuratie',
|
||||||
|
'test_connection' => 'Test Connectie',
|
||||||
|
'connection_success_title' => 'Success',
|
||||||
|
'connection_success_text' => 'Connectie succesvol',
|
||||||
|
'connection_error_title' => 'Error',
|
||||||
|
'connection_error_text' => 'Connectie error',
|
||||||
|
'companies' => 'Bedrijven',
|
||||||
|
'sync' => 'Sync',
|
||||||
|
'company_activated_title' => 'Geactiveerd',
|
||||||
|
'company_deactivated_title' => 'Gedeactiveerd',
|
||||||
|
'company_activated_text' => 'Bedrijf is geactiveerd.',
|
||||||
|
'company_deactivated_text' => 'Bedrijf is gedeactiveerd.',
|
||||||
|
'company_name' => 'Naam',
|
||||||
|
'company' => 'Bedrijf',
|
||||||
|
'company_id' => 'ID',
|
||||||
|
'company_debtor' => 'Debiteur',
|
||||||
|
'company_state' => 'Staat',
|
||||||
|
'server_count' => 'Aantal server(s)',
|
||||||
|
'show_all' => 'Zie alle',
|
||||||
|
'show_active' => 'Actieve',
|
||||||
|
'servers' => 'Servers',
|
||||||
|
'server_overview' => 'Server overzicht',
|
||||||
|
'dashboard_text_server_overview' => 'Bekijk het server overzicht',
|
||||||
|
'server_hostname' => 'Hostnaam',
|
||||||
|
'server_power_state' => 'Aan/Uit',
|
||||||
|
'server_state' => 'Status',
|
||||||
|
'server_os' => 'OS',
|
||||||
|
'server_cpu' => 'CPU',
|
||||||
|
'server_memory' => 'Mem',
|
||||||
|
'server_memory_demand' => 'Mem vbrk.',
|
||||||
|
'server_disks' => 'Schijven',
|
||||||
|
'server_ipv4' => 'IPv4',
|
||||||
|
'server_ipv6' => 'IPv6',
|
||||||
|
'server_vm_snapshot' => 'Snapshot',
|
||||||
|
'server_vm_generation' => 'Gen',
|
||||||
|
'server_licenses' => 'Licenties',
|
||||||
|
'server_backup' => 'Backups',
|
||||||
|
'disk_space' => 'Schijf grote',
|
||||||
|
'disk_used' => 'Schijf gebruikt',
|
||||||
|
'disk_location' => 'Schijf locatie',
|
||||||
|
'type' => 'Type',
|
||||||
|
'all_technical_information' => 'Alle technische informatie',
|
||||||
|
'avatar' => 'Avatar',
|
||||||
|
'user_state' => 'Staat',
|
||||||
|
'last_login' => 'Laatste login',
|
||||||
|
'description' => 'Beschrijving',
|
||||||
|
'name' => 'Naam',
|
||||||
|
'show_del' => 'del.',
|
||||||
|
];
|
||||||
13
pub/bin/pages/autop/pageDevices.php
Normal file
13
pub/bin/pages/autop/pageDevices.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (isset($_GET['add'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/autop/pageDevices_add.php');
|
||||||
|
} elseif (isset($_GET['edit'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/autop/pageDevices_edit.php');
|
||||||
|
} elseif (isset($_GET['view'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/autop/pageDevices_view.php');
|
||||||
|
} else {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/autop/pageDevices_list.php');
|
||||||
|
}
|
||||||
1
pub/bin/pages/autop/pageDevicesSettings.php
Normal file
1
pub/bin/pages/autop/pageDevicesSettings.php
Normal file
@@ -0,0 +1 @@
|
|||||||
|
to be made
|
||||||
195
pub/bin/pages/autop/pageDevices_add.php
Normal file
195
pub/bin/pages/autop/pageDevices_add.php
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_devices.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-devices', 'RW', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'] = true;
|
||||||
|
$jsScriptLoadData['slugify'] = true;
|
||||||
|
$jsScriptLoadData['datepicker'] = true;
|
||||||
|
$jsScriptLoadData['multiple_select'] = true;
|
||||||
|
$jsScriptLoadData['validateJson'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$pageNavbar->AddHTMLButton('<div class="btn-group dropdown">
|
||||||
|
<button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||||
|
<i class="fas fa-plus text-success"></i>' . __('add_device') . '</button>
|
||||||
|
<ul class="dropdown-menu bg-black2" role="menu">
|
||||||
|
<li>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=phone">Phone</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=module">Module</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=base">Base</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=handset">Handset</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>');
|
||||||
|
$add_get = htmlspecialchars($_GET['add'], ENT_QUOTES, 'UTF-8');
|
||||||
|
$formBuilder = new formBuilder('add_' . $add_get . '_device', '<i class="fas fa-plus"></i>', '/devices/');
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$formInputs = ['device_type', 'device_vendor_uuid', 'device_name', 'device_slugify', 'device_enabled', 'device_image', 'device_notes'];
|
||||||
|
if ($_GET['add'] == 'phone' || $_GET['add'] == 'base') {
|
||||||
|
$formInputs[] = 'device_eol';
|
||||||
|
$formInputs[] = 'device_extensions';
|
||||||
|
}
|
||||||
|
$formInputs[] = 'device_extra';
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('add_device'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
$formBuilder->startForm();
|
||||||
|
?>
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/devices">
|
||||||
|
<input type="hidden" name="_return" value="/devices/">
|
||||||
|
<div class="card-body">
|
||||||
|
<?php foreach ($formInputs as $input) {
|
||||||
|
if ($input == 'device_type') { ?>
|
||||||
|
<input type="hidden" name="device_type" value="<?php echo htmlspecialchars($_GET['add'], ENT_QUOTES, 'UTF-8'); ?>">
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_vendor_uuid') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_vendor_uuid" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_vendor') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="device_vendor_uuid" name="device_vendor_uuid" class="form-control" required>
|
||||||
|
<?php
|
||||||
|
$data = $GLOBALS['conn']->query("SELECT vendor_uuid, vendor_name FROM vc_vendors WHERE vendor_enabled = 1");
|
||||||
|
if ($data->num_rows == 0) { ?>
|
||||||
|
<option value=""><?php echo __('no_vendor_found') ?></option>
|
||||||
|
<?php } else {
|
||||||
|
while ($row = $data->fetch_assoc()) { ?>
|
||||||
|
<option value="<?php echo $row['vendor_uuid'] ?>"><?php echo $row['vendor_name'] ?></option>
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_name') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="device_name" name="device_name" data-slugify="device_slugify" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_slugify') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="device_slugify" name="device_slugify" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_enabled') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_enabled" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_enabled') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="device_enabled" name="device_enabled" class="form-control" required>
|
||||||
|
<option value="1" selected><?php echo __('enabled') ?></option>
|
||||||
|
<option value="0"><?php echo __('disabled') ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_notes') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_notes" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_notes') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<textarea class="form-control" id="device_notes" name="device_notes" rows="5"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_eol') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_eol" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('eol') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" class="form-control" id="device_eol" name="device_eol" data-datepicker="true" placeholder=""/>
|
||||||
|
<span class="input-group-text"><i class="fa fa-calendar-check"></i></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_image') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_image" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_image') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-file input-file-image">
|
||||||
|
<img class="img-upload-preview" width="200" src="/src/images/placeholder500x500.png" alt="preview">
|
||||||
|
<input type="file" class="form-control form-control-file" id="device_image" name="device_image" accept="image/png">
|
||||||
|
<label for="device_image" class="label-input-file btn btn-black btn-round">
|
||||||
|
<span class="btn-label"><i class="fa fa-file-image"></i></span>
|
||||||
|
<?php echo __('upload_image') ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_extensions') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_extensions" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_extensions') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="device_extensions" name="device_extensions[]" class="form-control" multiple="multiple" data-multiple-select="true">
|
||||||
|
<?php
|
||||||
|
$data = $GLOBALS['conn']->query("SELECT device_uuid, device_name, device_vendor_uuid FROM vc_devices WHERE device_type = 'module'");
|
||||||
|
if ($data->num_rows == 0) { ?>
|
||||||
|
<option value=""><?php echo __('no_device_found') ?></option>
|
||||||
|
<?php } else {
|
||||||
|
while ($row = $data->fetch_assoc()) { ?>
|
||||||
|
<option value="<?php echo $row['device_uuid'] ?>" data-vendor="<?php echo $row['device_vendor_uuid'] ?>">
|
||||||
|
<?php echo $row['device_name'] ?>
|
||||||
|
</option>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_extra') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_extra" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_extra') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<textarea class="form-control" id="device_extra" name="device_extra" rows="5" data-validate-json="true"></textarea>
|
||||||
|
<small id="device_extra_help" class="form-text text-muted">
|
||||||
|
<?php echo __('json_enter') ?>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
</div>
|
||||||
|
<?php $formBuilder->formFooter(); ?>
|
||||||
|
</form>
|
||||||
|
<?php $formBuilder->endForm(); ?>
|
||||||
220
pub/bin/pages/autop/pageDevices_edit.php
Normal file
220
pub/bin/pages/autop/pageDevices_edit.php
Normal file
@@ -0,0 +1,220 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_devices.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-devices', 'RW', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'][] = true;
|
||||||
|
$jsScriptLoadData['datepicker'] = true;
|
||||||
|
$jsScriptLoadData['multiple_select'] = true;
|
||||||
|
$jsScriptLoadData['validateJson'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$pageNavbar->AddHTMLButton('<div class="btn-group dropdown">
|
||||||
|
<button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||||
|
<i class="fas fa-plus text-success"></i>' . __('add_device') . '</button>
|
||||||
|
<ul class="dropdown-menu bg-black2" role="menu">
|
||||||
|
<li>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=phone">Phone</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=module">Module</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=base">Base</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=handset">Handset</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>');
|
||||||
|
$formBuilder = new formBuilder('edit_device', '<i class="fas fa-edit"></i>', '/devices/');
|
||||||
|
$get_edit = htmlspecialchars($_GET['edit'], ENT_QUOTES, 'UTF-8');
|
||||||
|
$formBuilder->addExtraButtons(array(0 => array('buttonText' => __('view'), 'buttonIcon' => '<i class="far fa-eye"></i>', 'buttonHref' => '?view=' . $get_edit, 'buttonColor' => 'info')));
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$device_found = false;
|
||||||
|
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM vc_devices INNER JOIN vc_vendors ON vc_devices.device_vendor_uuid = vc_vendors.vendor_uuid WHERE device_uuid = ?");
|
||||||
|
$stmt->bind_param("s", $_GET['edit']);
|
||||||
|
$stmt->execute();
|
||||||
|
$device_data_result = $stmt->get_result();
|
||||||
|
$device_data = $device_data_result->fetch_assoc();
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => $device_data['vendor_name'] . ' ' . $device_data['device_name'], 'href' => '?view=' . $device_data['device_uuid']));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('edit'), 'href' => '?view=' . $device_data['device_uuid']));
|
||||||
|
if ($device_data_result->num_rows > 0) {
|
||||||
|
$device_found = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$formInputs = ['device_vendor_uuid', 'device_name', 'device_slugify', 'device_enabled', 'device_image', 'device_notes'];
|
||||||
|
if ($device_data['device_type'] == 'phone' || $device_data['device_type'] == 'base') {
|
||||||
|
$formInputs[] = 'device_eol';
|
||||||
|
$formInputs[] = 'device_extensions';
|
||||||
|
}
|
||||||
|
$formInputs[] = 'device_extra';
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('devices'), 'href' => '/devices/'));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
|
||||||
|
if ($device_found) {
|
||||||
|
$formBuilder->startForm();
|
||||||
|
?>
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/devices">
|
||||||
|
<input type="hidden" name="_method" value="PUT">
|
||||||
|
<input type="hidden" name="_return" value="/devices/?edit=<?php echo $device_data['device_uuid']; ?>">
|
||||||
|
<input type="hidden" name="device_uuid" value="<?php echo $device_data['device_uuid'] ?>">
|
||||||
|
<div class="card-body">
|
||||||
|
<?php foreach ($formInputs as $input) {
|
||||||
|
if ($input == 'device_vendor_uuid') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_vendor_uuid" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_vendor') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="device_vendor_uuid" name="device_vendor_uuid" class="form-control" required>
|
||||||
|
<?php
|
||||||
|
$data = $GLOBALS['conn']->query("SELECT vendor_uuid, vendor_name FROM vc_vendors WHERE vendor_enabled = 1");
|
||||||
|
if ($data->num_rows == 0) { ?>
|
||||||
|
<option value=""><?php echo __('no_vendor_found') ?></option>
|
||||||
|
<?php } else {
|
||||||
|
while ($row = $data->fetch_assoc()) { ?>
|
||||||
|
<option value="<?php echo $row['vendor_uuid'] ?>" <?php echo(($row['vendor_uuid'] == $device_data['device_vendor_uuid']) ? 'selected' : '') ?>><?php echo $row['vendor_name'] ?></option>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_name') {
|
||||||
|
?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="device_name" name="device_name" value="<?php echo $device_data['device_name'] ?>" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_slugify') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="device_slugify" name="device_slugify" value="<?php echo $device_data['device_slugify'] ?>" placeholder="" disabled/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_enabled') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_enabled" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_enabled') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="device_enabled" name="device_enabled" class="form-control" required>
|
||||||
|
<option value="1" <?php echo(($device_data['device_enabled'] == 1) ? 'selected' : '') ?>><?php echo __('enabled') ?></option>
|
||||||
|
<option value="0" <?php echo(($device_data['device_enabled'] == 0) ? 'selected' : '') ?>><?php echo __('disabled') ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_notes') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_notes" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_notes') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<textarea class="form-control" id="device_notes" name="device_notes" rows="5"><?php echo $device_data['device_notes'] ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_eol') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_eol" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('eol') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" class="form-control" id="device_eol" value="<?php echo !empty($device_data['device_eol']) ? date('d/m/Y', $device_data['device_eol']) : ''; ?>" name="device_eol" placeholder="" data-datepicker="true"/>
|
||||||
|
<span class="input-group-text"><i class="fa fa-calendar-check"></i></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_image') { ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_image" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_image') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-file input-file-image">
|
||||||
|
<img class="img-upload-preview" width="200" src="<?php echo(($device_data['device_image'] != null) ? 'data:image/png;base64, ' . $device_data['device_image'] : '/src/images/placeholder500x500.png') ?>" alt="device_image">
|
||||||
|
<input type="file" class="form-control form-control-file" id="device_image" name="device_image" accept="image/png">
|
||||||
|
<label for="device_image" class="label-input-file btn btn-black btn-round">
|
||||||
|
<span class="btn-label"><i class="fa fa-file-image"></i></span>
|
||||||
|
<?php echo __('upload_image') ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_extensions') {
|
||||||
|
$device_extensions = json_decode($device_data['device_extensions']);
|
||||||
|
?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_extensions" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_extensions') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="device_extensions" name="device_extensions[]" class="form-control" multiple="multiple" data-multiple-select="true">
|
||||||
|
<?php
|
||||||
|
if ($device_data['device_type'] == 'base') {
|
||||||
|
$data = $GLOBALS['conn']->query("SELECT device_uuid, device_name, device_vendor_uuid FROM vc_devices WHERE device_type = 'module' OR device_type = 'handset'");
|
||||||
|
} else {
|
||||||
|
$data = $GLOBALS['conn']->query("SELECT device_uuid, device_name, device_vendor_uuid FROM vc_devices WHERE device_type = 'module'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($data->num_rows == 0) { ?>
|
||||||
|
<option value=""><?php echo __('no_device_found') ?></option>
|
||||||
|
<?php } else {
|
||||||
|
while ($row = $data->fetch_assoc()) { ?>
|
||||||
|
<option <?php echo(in_array($row['device_uuid'], $device_extensions) ? 'selected' : '') ?> value="<?php echo $row['device_uuid'] ?>" data-vendor="<?php echo $row['device_vendor_uuid'] ?>">
|
||||||
|
<?php echo $row['device_name'] ?>
|
||||||
|
</option>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($input == 'device_extra') {
|
||||||
|
$json_device_extra = json_encode(json_decode($device_data['device_extra']), JSON_PRETTY_PRINT); ?>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="device_extra" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('device_extra') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<textarea class="form-control" id="device_extra" name="device_extra" rows="5" data-validate-json="true"><?php echo $json_device_extra ?></textarea>
|
||||||
|
<small id="device_extra_help" class="form-text text-muted">
|
||||||
|
<?php echo __('json_enter') ?>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
</div>
|
||||||
|
<?php $formBuilder->formFooter(); ?>
|
||||||
|
</form>
|
||||||
|
<?php $formBuilder->endForm();
|
||||||
|
} else {
|
||||||
|
echo "No Vendor found with uuid " . $_GET['edit'];
|
||||||
|
|
||||||
|
}
|
||||||
105
pub/bin/pages/autop/pageDevices_list.php
Normal file
105
pub/bin/pages/autop/pageDevices_list.php
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_devices.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-devices', 'RO', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['multiFilterSelect'] = true;
|
||||||
|
$jsScriptLoadData['delete_confirmation'] = true;
|
||||||
|
$jsScriptLoadData['datatables'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(false, '<i class="fas fa-fax"></i> ' . __('devices'));
|
||||||
|
if ($API->checkPermissions('admin-devices', 'RW', true)) {
|
||||||
|
$pageNavbar->AddHTMLButton('<div class="btn-group dropdown">
|
||||||
|
<button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||||
|
<i class="fas fa-plus text-success"></i>' . __('add_device') . '</button>
|
||||||
|
<ul class="dropdown-menu bg-black2" role="menu">
|
||||||
|
<li>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=phone">Phone</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=module">Module</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=base">Base</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=handset">Handset</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>');
|
||||||
|
}
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$data = $GLOBALS['conn']->query("SELECT * FROM vc_devices INNER JOIN vc_vendors ON vc_devices.device_vendor_uuid = vc_vendors.vendor_uuid");
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('devices'), 'href' => '/devices/'));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
?>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="multi-filter-select table table-hover" data-skip-columns="0,5" data-datatables-order='[ [1, "desc"], [3, "asc"] ]' data-page-length="25">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Image</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Vendor</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Enabled</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th>Image</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Vendor</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Enabled</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
<?php while ($row = $data->fetch_assoc()) { ?>
|
||||||
|
<tr data-item-id="<?php echo $row['device_uuid']; ?>">
|
||||||
|
<td style="padding-top: 0px!important;padding-bottom: 0px!important;">
|
||||||
|
<img class="img-upload-preview" src="data:image/png;base64, <?php echo $row['device_image_thumbnail'] ?>" alt="">
|
||||||
|
</td>
|
||||||
|
<td><?php echo ucfirst($row['device_type']) ?></td>
|
||||||
|
<td><?php echo $row['vendor_name'] ?></td>
|
||||||
|
<td><?php echo $row['device_name'] ?></td>
|
||||||
|
<td>
|
||||||
|
<?php echo(($row['device_enabled'] == 1) ? __('yes') : __('no')) ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php if ($API->checkPermissions('admin-devices', 'RW', true)) { ?>
|
||||||
|
<a href="?edit=<?php echo $row['device_uuid'] ?>" class="btn btn-primary btn-sm btn-rounded"><i class="fas fa-edit"></i></a>
|
||||||
|
<?php } ?>
|
||||||
|
<a href="?view=<?php echo $row['device_uuid'] ?>" class="btn btn-info btn-sm btn-rounded"><i class="far fa-eye"></i></a>
|
||||||
|
<?php if ($API->checkPermissions('admin-devices', 'RW', true)) { ?>
|
||||||
|
<a href="#" class="btn btn-danger btn-sm btn-rounded delete-btn" data-item-uuid="<?php echo $row['device_uuid'] ?>" data-api-url="/api/v1/devices/" data-item-name="device_uuid"><i class="fas fa-trash-alt"></i></a>
|
||||||
|
<?php } ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
420
pub/bin/pages/autop/pageDevices_view.php
Normal file
420
pub/bin/pages/autop/pageDevices_view.php
Normal file
@@ -0,0 +1,420 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_devices.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-devices', 'RO', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
function showExtension($devicesLinked, $filter = false)
|
||||||
|
{
|
||||||
|
if (count($devicesLinked) > 0) {
|
||||||
|
foreach ($devicesLinked as $extension) {
|
||||||
|
if ($filter === false || $extension['device_type'] == $filter) { ?>
|
||||||
|
<div class="col-sm-3 d-flex flex-column align-items-center">
|
||||||
|
<img src="data:image/png;base64, <?php echo $extension['device_image']; ?>" class="img-fluid pb-4" style="max-width: 100%; height: auto;" alt="...">
|
||||||
|
<a href="?view=<?php echo $extension['device_uuid'] ?>" class="btn btn-info btn-rounded align-items-center"><?php echo $extension['device_name'] ?></a>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
|
} else { ?>
|
||||||
|
<p><?php echo __('no_device_found') ?></p>
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeFileTables($API, $dataFolder, $device_slugify)
|
||||||
|
{
|
||||||
|
$device_data_dir = $_SERVER['DOCUMENT_ROOT'] . '/data/devices/' . $device_slugify . '/' . $dataFolder . '/';
|
||||||
|
$documents = array_diff(scandir($device_data_dir), array('..', '.'));
|
||||||
|
|
||||||
|
foreach ($documents as $document) {
|
||||||
|
$full_path = $device_data_dir . $document;
|
||||||
|
$fileSize = human_filesize(fileSize($full_path));
|
||||||
|
$fileModified = date("Y-m-d H:i:s", filemtime($full_path));
|
||||||
|
$urlPath = '/data/devices/' . $device_slugify . '/' . $dataFolder . '/' . $document;
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a target="_blank" href="<?php echo $urlPath ?>"><i class="fas fa-external-link-alt"></i> <?php echo $document; ?>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $fileSize ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo $fileModified ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php if ($API->checkPermissions('admin-devices-files', 'RW', true)) { ?>
|
||||||
|
<form action="/api/v1/devices/files" method="post">
|
||||||
|
<input type="hidden" name="filePath" value="">
|
||||||
|
<input type="hidden" name="_method" value="DELETE">
|
||||||
|
<a href="#" class="btn btn-danger btn-sm btn-rounded delete-btn" data-item-uuid="<?php echo $urlPath ?>" data-api-url="/api/v1/devices/files/" data-item-name="file_name"><i class="fas fa-trash-alt"></i></a>
|
||||||
|
</form>
|
||||||
|
<?php } ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
|
|
||||||
|
function render_template_controls($template_uuid, $device_uuid, $default_template, $platform_uuid)
|
||||||
|
{
|
||||||
|
?>
|
||||||
|
<div class="d-flex align-items-center gap-2">
|
||||||
|
<form id="add_<?php echo $default_template ?>_template" action="/api/v2/templates/add/" method="post" <?= $template_uuid ? 'style="display: none"' : '' ?>>
|
||||||
|
<input type="hidden" name="template_device_uuid" value="<?= htmlspecialchars($device_uuid) ?>">
|
||||||
|
<input type="hidden" name="template_name" value="<?php echo $default_template ?>">
|
||||||
|
<input type="hidden" name="template_slugify" value="<?php echo $default_template ?>">
|
||||||
|
<?php if ($platform_uuid) { ?>
|
||||||
|
<input type="hidden" name="platform_uuid" value="<?php echo $platform_uuid ?>">
|
||||||
|
<?php } ?>
|
||||||
|
<button type="submit" class="btn btn-success btn-rounded mt-2" disabled>
|
||||||
|
<i class="fas fa-magic"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<a id="edit_<?php echo $default_template ?>_template" class="btn btn-primary btn-rounded" href="/devices/?template=<?= htmlspecialchars($template_uuid) ?>" <?= !$template_uuid ? 'style="display: none"' : '' ?>><i class="fas fa-edit" disabled=""></i></a>
|
||||||
|
|
||||||
|
<form id="del_<?php echo $default_template ?>_template" action="/api/v1/templates/del/" method="post" <?= !$template_uuid ? 'style="display: none"' : '' ?>>
|
||||||
|
<input type="hidden" name="template_uuid" value="<?= htmlspecialchars($template_uuid) ?>">
|
||||||
|
<a href="#" class="btn btn-danger btn-rounded delete-btn" data-item-uuid="<?= htmlspecialchars($template_uuid) ?>" data-api-url="/api/v2/templates/del/" data-delete-action='{"add_<?php echo $default_template ?>_template":"show", "edit_<?php echo $default_template ?>_template":"hide", "del_<?php echo $default_template ?>_template":"hide"}'><i class="fas fa-trash-alt"></i></a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['delete_confirmation'][] = true;
|
||||||
|
$jsScriptLoadData['load_dropzone'] = true;
|
||||||
|
$jsScriptLoadData['form'][] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
if ($API->checkPermissions('admin-devices', 'RW', true)) {
|
||||||
|
$pageNavbar->AddHTMLButton('<button class="btn btn-danger" type="button" disabled><i class="fas fa-trash-alt"></i> ' . __('delete') . '</button>');
|
||||||
|
$get_view = htmlspecialchars($_GET['view'], ENT_QUOTES, 'UTF-8');
|
||||||
|
$pageNavbar->AddHTMLButton('<a class="btn btn-primary mx-3" type="button" href="?edit=' . $get_view . '"><i class="fas fa-edit"></i> ' . __('edit') . '</a>');
|
||||||
|
$pageNavbar->AddHTMLButton('<div class="btn-group dropdown">
|
||||||
|
<button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||||
|
<i class="fas fa-plus text-success"></i> ' . __('add_device') . '</button>
|
||||||
|
<ul class="dropdown-menu bg-black2" role="menu">
|
||||||
|
<li>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=phone">Phone</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=module">Module</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=base">Base</a>
|
||||||
|
<a class="dropdown-item text-white-50 bg-black2" href="?add=handset">Handset</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>');
|
||||||
|
}
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM vc_devices INNER JOIN vc_vendors ON vc_devices.device_vendor_uuid = vc_vendors.vendor_uuid WHERE device_uuid = ?");
|
||||||
|
$stmt->bind_param("s", $_GET['view']);
|
||||||
|
$stmt->execute();
|
||||||
|
$device_data_result = $stmt->get_result();
|
||||||
|
if ($device_data_result->num_rows == 0) {
|
||||||
|
echo "No Vendor found with uuid " . htmlspecialchars($_GET['edit'], ENT_QUOTES, 'UTF-8');
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
$device_data = $device_data_result->fetch_assoc();
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('devices'), 'href' => '/devices/'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => $device_data['vendor_name'] . ' ' . $device_data['device_name'], 'href' => '?view=' . $device_data['device_uuid']));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="row d-flex align-items-stretch pb-2">
|
||||||
|
<div class="col-md-4 pb-4">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<h1 class="text-center"><?php echo $device_data['vendor_name'] . ' ' . $device_data['device_name'] ?></h1>
|
||||||
|
<img src="data:image/png;base64, <?php echo $device_data['device_image']; ?>" class="img-fluid" style="max-width: 100%; height: auto;" alt="...">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8 pb-4">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>vendor_name:</td>
|
||||||
|
<td><?php echo $device_data['vendor_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>device_uuid:</td>
|
||||||
|
<td><?php echo $device_data['device_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>device_type:</td>
|
||||||
|
<td><?php echo $device_data['device_type'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>device_name:</td>
|
||||||
|
<td><?php echo $device_data['device_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>device_slugify:</td>
|
||||||
|
<td><?php echo $device_data['device_slugify'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>device_enabled:</td>
|
||||||
|
<td><?php echo $device_data['device_enabled'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>device_eol:</td>
|
||||||
|
<td><?php echo showTime($device_data['device_eol']) ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>device_create_timestamp:</td>
|
||||||
|
<td><?php echo showTime($device_data['device_create_timestamp']) ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>device_modified_timestamp: </td>
|
||||||
|
<td><?php echo showTime($device_data['device_modified_timestamp']) ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="align-top">device_notes:</td>
|
||||||
|
<td><?php echo $device_data['device_notes'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="align-top">device_extra:</td>
|
||||||
|
<td class="w-100">
|
||||||
|
<textarea class="form-control" id="device_extra" name="device_extra" rows="5" disabled><?php echo json_encode(json_decode($device_data['device_extra']), JSON_PRETTY_PRINT) ?></textarea>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header pt-2 pb-1">
|
||||||
|
<h4>Uses</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
To be made. Its going to be visible where the device is used (organisation/site).
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<?php
|
||||||
|
# Retrieve device extension data from the device
|
||||||
|
$devicesLinked = array();
|
||||||
|
if ($device_data['device_type'] == 'phone' || $device_data['device_type'] == 'base') {
|
||||||
|
$device_extensions = json_decode($device_data['device_extensions']);
|
||||||
|
} elseif ($device_data['device_type'] == 'module' || $device_data['device_type'] == 'handset') {
|
||||||
|
$query = "SELECT device_extensions, device_uuid FROM vc_devices WHERE device_extensions LIKE ?";
|
||||||
|
$stmt = $GLOBALS['conn']->prepare($query);
|
||||||
|
if ($stmt) {
|
||||||
|
$searchTerm = "%" . $device_data['device_uuid'] . "%"; // Add wildcards manually
|
||||||
|
$stmt->bind_param('s', $searchTerm);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
$device_extensions = array();
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
array_push($device_extensions, $row['device_uuid']);
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($device_extensions)) {
|
||||||
|
$placeholders = implode(' OR device_uuid = ', array_fill(0, count($device_extensions), '?'));
|
||||||
|
$query = "SELECT * FROM vc_devices WHERE device_uuid = " . $placeholders;
|
||||||
|
$stmt = $GLOBALS['conn']->prepare($query);
|
||||||
|
if ($stmt) {
|
||||||
|
$types = str_repeat('s', count($device_extensions));
|
||||||
|
$stmt->bind_param($types, ...$device_extensions);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
array_push($devicesLinked, $row);
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$connectedDeviceCards = [];
|
||||||
|
if (in_array($device_data['device_type'], ['phone', 'base'])) {
|
||||||
|
$connectedDeviceCards[] = [
|
||||||
|
'title' => __('extensions_available'),
|
||||||
|
'filter' => 'module'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($device_data['device_type'] == 'base') {
|
||||||
|
$connectedDeviceCards[] = [
|
||||||
|
'title' => __('handsets_available'),
|
||||||
|
'filter' => 'handset'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($device_data['device_type'], ['module', 'handset'])) {
|
||||||
|
$connectedDeviceCards[] = [
|
||||||
|
'title' => __('parent_device'),
|
||||||
|
'filter' => false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($connectedDeviceCards as $card) { ?>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header pt-2 pb-1">
|
||||||
|
<h4><?php echo $card['title']; ?></h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row">
|
||||||
|
<?php showExtension($devicesLinked, $card['filter']); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body pt-0">
|
||||||
|
<ul class="nav nav-tabs nav-line nav-color-secondary" id="line-tab" role="tablist">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link active" id="line-home-tab" data-bs-toggle="pill" href="#line-home" role="tab" aria-controls="pills-home" aria-selected="true">Documents</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" id="line-profile-tab" data-bs-toggle="pill" href="#line-profile" role="tab" aria-controls="pills-profile" aria-selected="false">Firmware</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content mt-3 mb-3" id="line-tabContent">
|
||||||
|
<div class="tab-pane fade show active" id="line-home" role="tabpanel" aria-labelledby="line-home-tab">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-borderless " data-table-type="documents">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('document') ?></th>
|
||||||
|
<th><?php echo __('filesize') ?></th>
|
||||||
|
<th><?php echo __('file_last_modified') ?></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php makeFileTables($API, 'documents', $device_data['device_slugify']); ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php if ($API->checkPermissions('admin-devices-files', 'RW', true)) { ?>
|
||||||
|
<form action="/api/v1/devices/files" class="dropzone p-0" data-form-type="documents">
|
||||||
|
<input type="hidden" name="device_slugify" value="<?php echo $device_data['device_slugify'] ?>">
|
||||||
|
<input type="hidden" name="filetype" value="documents">
|
||||||
|
<div class="dz-message mt-1 mb-0" data-dz-message>
|
||||||
|
<div class="icon">
|
||||||
|
<i class="icon-doc"></i>
|
||||||
|
</div>
|
||||||
|
<h4 class="message"><?php echo __('drag_and_drop_files_here') ?> </h4>
|
||||||
|
</div>
|
||||||
|
<div class="fallback">
|
||||||
|
<input name="file" type="file" multiple/>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane fade" id="line-profile" role="tabpanel" aria-labelledby="line-profile-tab">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-borderless" data-table-type="firmware">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('filename') ?></th>
|
||||||
|
<th><?php echo __('filesize') ?></th>
|
||||||
|
<th><?php echo __('file_last_modified') ?></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php makeFileTables($API, 'firmware', $device_data['device_slugify']); ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<form action="/api/v1/devices/files" class="dropzone p-0" data-form-type="firmware">
|
||||||
|
<input type="hidden" name="device_slugify" value="<?php echo $device_data['device_slugify'] ?>">
|
||||||
|
<input type="hidden" name="filetype" value="firmware">
|
||||||
|
<div class="dz-message mt-1 mb-0" data-dz-message>
|
||||||
|
<div class="icon">
|
||||||
|
<i class="icon-doc"></i>
|
||||||
|
</div>
|
||||||
|
<h4 class="message"><?php echo __('drag_and_drop_files_here') ?> </h4>
|
||||||
|
</div>
|
||||||
|
<div class="fallback">
|
||||||
|
<input name="file" type="file" multiple/>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
$device_uuid = $device_data['device_uuid'] ?? null;
|
||||||
|
$platforms_enabled = get_enabled_platforms($GLOBALS['conn']);
|
||||||
|
$default_template_uuid = 0 // to be made
|
||||||
|
?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header pt-2 pb-1">
|
||||||
|
<h4><?= __('templates') ?></h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body pt-0">
|
||||||
|
<div class="row">
|
||||||
|
<!-- Default Template -->
|
||||||
|
<div class="col-sm-3 d-flex">
|
||||||
|
<div class="card flex-fill d-flex flex-column">
|
||||||
|
<div class="card-body d-flex flex-column">
|
||||||
|
<h4><?= __('default') ?></h4>
|
||||||
|
<img src="/src/images/default-template-icon.png" alt="" class="img-fluid pb-3 flex-grow-1" style="object-fit: contain;">
|
||||||
|
<?php render_template_controls($default_template_uuid, $device_uuid, 'default', false); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Platform Templates -->
|
||||||
|
<?php foreach ($platforms_enabled as $platform) { ?>
|
||||||
|
<div class="col-sm-3 d-flex">
|
||||||
|
<div class="card flex-fill d-flex flex-column">
|
||||||
|
<div class="card-body d-flex flex-column">
|
||||||
|
<h4><?= htmlspecialchars($platform['data']['platform_name']) ?></h4>
|
||||||
|
<img src="data:image/jpeg;base64, <?= htmlspecialchars($platform['data']['platform_image']) ?>" alt="" class="img-fluid pb-3 flex-grow-1" style="object-fit: contain;">
|
||||||
|
<?php render_template_controls($platform['default_template_uuid'], $device_uuid, $platform['data']['platform_slugify'], $platform['data']['platform_uuid']); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
4
pub/bin/pages/autop/pagePhonebooks.php
Normal file
4
pub/bin/pages/autop/pagePhonebooks.php
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
to be made
|
||||||
|
<div class="alert alert-gruvbox">Gruvbox styled alert</div>
|
||||||
|
<pre>
|
||||||
|
<?php
|
||||||
11
pub/bin/pages/autop/pagePlatforms.php
Normal file
11
pub/bin/pages/autop/pagePlatforms.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (isset($_GET['add'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/autop/pagePlatforms_add.php');
|
||||||
|
} elseif (isset($_GET['edit'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/autop/pagePlatforms_edit.php');
|
||||||
|
} else {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/autop/pagePlatforms_list.php');
|
||||||
|
}
|
||||||
96
pub/bin/pages/autop/pagePlatforms_add.php
Normal file
96
pub/bin/pages/autop/pagePlatforms_add.php
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-access-control-permissions', 'RW', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'] = true;
|
||||||
|
$jsScriptLoadData['slugify'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$pageNavbar->AddHTMLButton('<a href="?add="><button class="btn btn-primary"><i class="fas fa-plus text-success"></i>' . __('add_platform') . '</button></a>');
|
||||||
|
$formBuilder = new formBuilder('add_platform', '<i class="fas fa-edit"></i>', '/platforms/',);
|
||||||
|
$formBuilder->submitButtonText = __('save');
|
||||||
|
$formBuilder->submitButtonIcon = '<i class="fas fa-save"></i>';
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('platforms'), 'href' => '/platforms/'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('add_platform'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
$formBuilder->startForm();
|
||||||
|
?>
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/platforms">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="platform_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="platform_name" name="platform_name" placeholder="" data-slugify="platform_slugify" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="platform_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="platform_slugify" name="platform_slugify" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="platform_enabled" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_enabled') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="platform_enabled" name="platform_enabled" class="form-control" required>
|
||||||
|
<option value="1" selected><?php echo __('enabled') ?></option>
|
||||||
|
<option value="0"><?php echo __('disabled') ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="platform_description" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_description') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<textarea class="form-control" id="platform_description" name="platform_description" rows="5"> </textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="platform_image" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_image') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-file input-file-image">
|
||||||
|
<img class="img-upload-preview" width="200" src="/src/images/placeholder200x200.png" alt="preview">
|
||||||
|
<input type="file" class="form-control form-control-file" id="platform_image" name="platform_image" accept="image/png">
|
||||||
|
<label for="platform_image" class="label-input-file btn btn-black btn-round">
|
||||||
|
<span class="btn-label"><i class="fa fa-file-image"></i></span>
|
||||||
|
<?php echo __('upload_image') ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $formBuilder->formFooter(); ?>
|
||||||
|
</form>
|
||||||
|
<?php $formBuilder->endForm(); ?>
|
||||||
119
pub/bin/pages/autop/pagePlatforms_edit.php
Normal file
119
pub/bin/pages/autop/pagePlatforms_edit.php
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use api\classes\API_platforms;
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_platforms.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-platforms', 'RW', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$pageNavbar->AddHTMLButton('<a href="?add="><button class="btn btn-primary"><i class="fas fa-plus text-success"></i>' . __('add_platform') . '</button></a>');
|
||||||
|
|
||||||
|
$formBuilder = new formBuilder('edit_platform', '<i class="fas fa-edit"></i>', '/platforms/',);
|
||||||
|
$formBuilder->submitButtonText = __('save');
|
||||||
|
$formBuilder->submitButtonIcon = '<i class="fas fa-save"></i>';
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$platform_uuid = $_GET['edit'];
|
||||||
|
$_GET['platform_uuid'] = $platform_uuid;
|
||||||
|
$API_platforms = new API_platforms();
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'platform_uuid', 1 => $platform_uuid]]];
|
||||||
|
$requiredFields = ['platform_uuid' => ['type' => 'uuid']];
|
||||||
|
$API_platforms->validateData($requiredFields);
|
||||||
|
$platform_data = $API_platforms->getPlatforms()[0];
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('platforms'), 'href' => '/platforms/'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('edit_platform'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
if ($platform_data) {
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
$formBuilder->startForm();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/platforms">
|
||||||
|
<input type="hidden" name="platform_uuid" value="<?php echo $platform_data["platform_uuid"] ?>">
|
||||||
|
<input type="hidden" name="_method" value="PUT">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="platform_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="platform_name" name="platform_name" placeholder="" value="<?php echo $platform_data['platform_name'] ?>" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="platform_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="platform_slugify" name="platform_slugify" placeholder="" value="<?php echo $platform_data['platform_slugify'] ?>" required disabled>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="platform_enabled" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_enabled') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="platform_enabled" name="platform_enabled" class="form-control" required>
|
||||||
|
<option value="1" <?php echo(($platform_data['platform_enabled'] == 1) ? 'selected' : '') ?>><?php echo __('enabled') ?></option>
|
||||||
|
<option value="0" <?php echo(($platform_data['platform_enabled'] == 0) ? 'selected' : '') ?>><?php echo __('disabled') ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="platform_description" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_description') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<textarea class="form-control" id="platform_description" name="platform_description" rows="5"><?php echo $platform_data['platform_description'] ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="platform_image" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('platform_image') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-file input-file-image">
|
||||||
|
<img class="img-upload-preview" width="200" src="data:image/png;base64, <?php echo $platform_data['platform_image'] ?>" alt="preview">
|
||||||
|
<input type="file" class="form-control form-control-file" id="platform_image" name="platform_image" accept="image/png">
|
||||||
|
<label for="platform_image" class="label-input-file btn btn-black btn-round">
|
||||||
|
<span class="btn-label"><i class="fa fa-file-image"></i></span>
|
||||||
|
<?php echo __('upload_image') ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
$formBuilder->formFooter();
|
||||||
|
?>
|
||||||
|
</form>
|
||||||
|
<?php
|
||||||
|
$formBuilder->endForm();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
echo "No Platform found with uuid " . htmlspecialchars($_GET['edit'], ENT_QUOTES, 'UTF-8');
|
||||||
|
}
|
||||||
101
pub/bin/pages/autop/pagePlatforms_list.php
Normal file
101
pub/bin/pages/autop/pagePlatforms_list.php
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-platforms', 'RO', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(false, '<i class="fas fa-layer-group"></i> Platforms');
|
||||||
|
$pageNavbar->AddHTMLButton('<a href="?add="><button class="btn btn-primary"><i class="fas fa-plus text-success"></i>' . __('add_platform') . '</button></a>');
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$data = $GLOBALS['conn']->query("SELECT * FROM vc_platforms");
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
?>
|
||||||
|
<div class="row g-3 align-items-stretch">
|
||||||
|
<?php while ($row = $data->fetch_assoc()) { ?>
|
||||||
|
<div class="col-md-4 px-2">
|
||||||
|
<div class="card card-post card-round h-100">
|
||||||
|
<img class="card-img-top img-fluid px-3" src="data:image/png;base64, <?php echo $row['platform_image'] ?>" alt="Card image cap" style="height: 200px; object-fit: scale-down;">
|
||||||
|
<div class="card-body">
|
||||||
|
<h3 class="card-title">
|
||||||
|
<?php
|
||||||
|
echo $row['platform_name'];
|
||||||
|
if ($row['platform_enabled']) {
|
||||||
|
echo ' <i class="fas fa-toggle-on text-success"></i>';
|
||||||
|
} else {
|
||||||
|
echo ' <i class="fas fa-toggle-off text-danger"></i>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</h3>
|
||||||
|
<p class="card-text"><?php echo $row['platform_description'] ?></p>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer pb-3 end-0 justify-content-end">
|
||||||
|
<?php if ($API->checkPermissions('admin-platforms', 'RW', true)) { ?>
|
||||||
|
<a href="?edit=<?php echo $row['platform_uuid'] ?>" class="btn btn-primary btn-sm">
|
||||||
|
<i class="fas fa-edit"></i> <?php echo __('edit') ?>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-platforms', 'RO', true)) { ?>
|
||||||
|
<a href="#" class="btn btn-info btn-sm" data-bs-toggle="modal" data-bs-target="#infoModal<?php echo $row['platform_name'] ?>">
|
||||||
|
<i class="fas fa-info-circle"></i> <?php echo __('info') ?>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal fade" id="infoModal<?php echo $row['platform_name'] ?>" tabindex="-1" aria-labelledby="infoModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered modal-lg">
|
||||||
|
<div class="modal-content bg-black2">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="infoModalLabel">
|
||||||
|
<i class="fas fa-info-circle"></i> <?php echo __('information') ?>
|
||||||
|
</h5>
|
||||||
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<br>
|
||||||
|
<table class="table table-sm table-striped-bg-black">
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('uuid') ?>:</td>
|
||||||
|
<td><?php echo $row['platform_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('create_date') ?>:</td>
|
||||||
|
<td><?php echo showTime($row['platform_create_timestamp']) ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('last_modified_date') ?>:</td>
|
||||||
|
<td><?php showTime($row['platform_modified_timestamp']) ?></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
1
pub/bin/pages/autop/pageProvisioning.php
Normal file
1
pub/bin/pages/autop/pageProvisioning.php
Normal file
@@ -0,0 +1 @@
|
|||||||
|
to be made
|
||||||
11
pub/bin/pages/autop/pageVendors.php
Normal file
11
pub/bin/pages/autop/pageVendors.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (isset($_GET['add'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/autop/pageVendors_add.php');
|
||||||
|
} elseif (isset($_GET['edit'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/autop/pageVendors_edit.php');
|
||||||
|
} else {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/autop/pageVendors_list.php');
|
||||||
|
}
|
||||||
101
pub/bin/pages/autop/pageVendors_add.php
Normal file
101
pub/bin/pages/autop/pageVendors_add.php
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_vendors.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-vendors', 'RW', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'] = true;
|
||||||
|
$jsScriptLoadData['slugify'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$pageNavbar->AddHTMLButton('<a href="?add="><button class="btn btn-primary"><i class="fas fa-plus text-success"></i>' . __('add_vendor') . '</button></a>');
|
||||||
|
|
||||||
|
$formBuilder = new formBuilder('add_vendor', '<i class="fas fa-plus"></i>', '/vendors/');
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('add_vendor'), 'href' => '/vendors/'));
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
$formBuilder->startForm();
|
||||||
|
?>
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/vendors">
|
||||||
|
<input type="hidden" name="_return" value="/vendors/">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="vendor_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="vendor_name" name="vendor_name" placeholder="" required data-slugify="vendor_slugify"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="vendor_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="vendor_slugify" name="vendor_slugify" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="vendor_enabled" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_enabled') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="vendor_enabled" name="vendor_enabled" class="form-control" required>
|
||||||
|
<option value="1" selected><?php echo __('enabled') ?></option>
|
||||||
|
<option value="0"><?php echo __('disabled') ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="vendor_description" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_description') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<textarea class="form-control" id="vendor_description" name="vendor_description" rows="5"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="vendor_image" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_image') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-file input-file-image">
|
||||||
|
<img class="img-upload-preview" width="200" src="/src/images/placeholder200x200.png" alt="preview">
|
||||||
|
<input type="file" class="form-control form-control-file" id="vendor_image" name="vendor_image" accept="image/png">
|
||||||
|
<label for="vendor_image" class="label-input-file btn btn-black btn-round">
|
||||||
|
<span class="btn-label"><i class="fa fa-file-image"></i></span>
|
||||||
|
<?php echo __('upload_image') ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$formBuilder->formFooter();
|
||||||
|
?>
|
||||||
|
</form>
|
||||||
|
<?php $formBuilder->endForm(); ?>
|
||||||
115
pub/bin/pages/autop/pageVendors_edit.php
Normal file
115
pub/bin/pages/autop/pageVendors_edit.php
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use api\classes\API_vendors;
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_vendors.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-vendors', 'RW', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$pageNavbar->AddHTMLButton('<a href="?add="><button class="btn btn-primary"><i class="fas fa-plus text-success"></i>' . __('add_vendor') . '</button></a>');
|
||||||
|
|
||||||
|
$formBuilder = new formBuilder('edit_vendor', '<i class="fas fa-edit"></i>', '/vendors/',);
|
||||||
|
$formBuilder->submitButtonText = __('save');
|
||||||
|
$formBuilder->submitButtonIcon = '<i class="fas fa-save"></i>';
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$vendor_uuid = htmlspecialchars($_GET['edit'], ENT_QUOTES, 'UTF-8');
|
||||||
|
$_GET['vendor_uuid'] = $vendor_uuid;
|
||||||
|
$API_vendors = new API_vendors();
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'vendor_uuid', 1 => $vendor_uuid]]];
|
||||||
|
$requiredFields = ['vendor_uuid' => ['type' => 'uuid']];
|
||||||
|
$API_vendors->validateData($requiredFields);
|
||||||
|
$vendor_data = $API_vendors->getVendors()[0];
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('edit_vendor'), 'href' => '/vendors/'));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
$formBuilder->startForm();
|
||||||
|
if ($vendor_data) { ?>
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/vendors">
|
||||||
|
<input type="hidden" name="vendor_uuid" value="<?php echo $vendor_data["vendor_uuid"] ?>">
|
||||||
|
<input type="hidden" name="_method" value="PUT">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="vendor_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="vendor_name_edit" name="vendor_name" placeholder="" value="<?php echo $vendor_data['vendor_name'] ?>" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="vendor_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="vendor_slugify_edit" name="vendor_slugify" placeholder="" value="<?php echo $vendor_data['vendor_slugify'] ?>" required disabled>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="vendor_enabled" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_enabled') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="vendor_enabled" name="vendor_enabled" class="form-control" required>
|
||||||
|
<option value="1" <?php echo(($vendor_data['vendor_enabled'] == 1) ? 'selected' : '') ?>><?php echo __('enabled') ?></option>
|
||||||
|
<option value="0" <?php echo(($vendor_data['vendor_enabled'] == 0) ? 'selected' : '') ?>><?php echo __('disabled') ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="vendor_description" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_description') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<textarea class="form-control" id="vendor_description" name="vendor_description" rows="5"><?php echo $vendor_data['vendor_description'] ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="vendor_image" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('vendor_image') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-file input-file-image">
|
||||||
|
<img class="img-upload-preview" width="200" src="data:image/png;base64, <?php echo $vendor_data['vendor_image'] ?>" alt="preview">
|
||||||
|
<input type="file" class="form-control form-control-file" id="vendor_image" name="vendor_image" accept="image/png">
|
||||||
|
<label for="vendor_image" class="label-input-file btn btn-black btn-round">
|
||||||
|
<span class="btn-label"><i class="fa fa-file-image"></i></span>
|
||||||
|
<?php echo __('upload_image') ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
$formBuilder->formFooter();
|
||||||
|
?>
|
||||||
|
</form>
|
||||||
|
<?php
|
||||||
|
$formBuilder->endForm();
|
||||||
|
} else {
|
||||||
|
echo "No Vendor found with uuid " . htmlspecialchars($_GET['edit'], ENT_QUOTES, 'UTF-8');
|
||||||
|
}
|
||||||
107
pub/bin/pages/autop/pageVendors_list.php
Normal file
107
pub/bin/pages/autop/pageVendors_list.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use api\classes\API_vendors;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
// N/A
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_vendors.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-vendors', 'RO', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions;
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(false, '<i class="fas fa-microchip"></i> ' . __('vendors'));
|
||||||
|
$pageNavbar->AddHTMLButton('<a href="?add="><button class="btn btn-primary"><i class="fas fa-plus text-success"></i>' . __('add_vendor') . '</button></a>');
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$API_vendors = new API_vendors();
|
||||||
|
$vendors_data = $API_vendors->getVendors();
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="row g-3 align-items-stretch">
|
||||||
|
<?php
|
||||||
|
foreach ($vendors_data as $vendor_data) { ?>
|
||||||
|
<div class="col-md-4 px-2">
|
||||||
|
<div class="card card-post card-round h-100">
|
||||||
|
<img class="card-img-top img-fluid px-3" src="data:image/png;base64, <?php echo $vendor_data['vendor_image'] ?>" alt="Card image cap" style="height: 200px; object-fit: scale-down;">
|
||||||
|
<div class="card-body">
|
||||||
|
<h3 class="card-title">
|
||||||
|
<?php
|
||||||
|
echo $vendor_data['vendor_name'];
|
||||||
|
if ($vendor_data['vendor_enabled']) {
|
||||||
|
echo ' <i class="fas fa-toggle-on text-success"></i>';
|
||||||
|
} else {
|
||||||
|
echo ' <i class="fas fa-toggle-off text-danger"></i>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</h3>
|
||||||
|
<p class="card-text"><?php echo $vendor_data['vendor_description'] ?></p>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer pb-3 end-0 justify-content-end">
|
||||||
|
<?php if ($API->checkPermissions('admin-vendors', 'RW', true)) { ?>
|
||||||
|
<a href="?edit=<?php echo $vendor_data['vendor_uuid'] ?>" class="btn btn-primary btn-sm">
|
||||||
|
<i class="fas fa-edit"></i> <?php echo __('edit') ?>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-vendors', 'RO', true)) { ?>
|
||||||
|
<a href="#" class="btn btn-info btn-sm" data-bs-toggle="modal" data-bs-target="#infoModal<?php echo $vendor_data['vendor_name'] ?>">
|
||||||
|
<i class="fas fa-info-circle"></i> <?php echo __('info') ?>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal fade" id="infoModal<?php echo $vendor_data['vendor_name'] ?>" tabindex="-1" aria-labelledby="infoModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered modal-lg">
|
||||||
|
<div class="modal-content bg-black2">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="infoModalLabel">
|
||||||
|
<i class="fas fa-info-circle"></i> <?php echo __('information') ?>
|
||||||
|
</h5>
|
||||||
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<br>
|
||||||
|
<table class="table table-sm table-striped-bg-black">
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('uuid') ?>:</td>
|
||||||
|
<td><?php echo $vendor_data['vendor_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('create_date') ?>:</td>
|
||||||
|
<td><?php showTime($vendor_data['vendor_create_timestamp']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('last_modified_date') ?>:</td>
|
||||||
|
<td><?php showTime($vendor_data['vendor_modified_timestamp']); ?></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
9
pub/bin/pages/customers/pageCompanies.php
Normal file
9
pub/bin/pages/customers/pageCompanies.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (isset($_GET['view'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/customers/pageCompanies_company_view.php');
|
||||||
|
} else {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/customers/pageCompanies_view.php');
|
||||||
|
}
|
||||||
93
pub/bin/pages/customers/pageCompanies_company_view.php
Normal file
93
pub/bin/pages/customers/pageCompanies_company_view.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php';
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('customer-companies', 'RO', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['datepicker'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$company_uuid = htmlspecialchars($_GET['view'], ENT_QUOTES, 'UTF-8');
|
||||||
|
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM companies WHERE company_uuid = ?");
|
||||||
|
$stmt->bind_param('s', $company_uuid);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
$company_data = $result->fetch_assoc();
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('companies'), 'href' => '/companies/'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => $company_data['company_name'], 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row">
|
||||||
|
<h1>
|
||||||
|
<i class="<?php echo $GLOBALS['pages']['customers']['companies']['page_icon'] ?>"></i> <?php echo $company_data['company_name'] ?>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 col-lg-6">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>company_uuid:</td>
|
||||||
|
<td><?php echo $company_data['company_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>source_uuid:</td>
|
||||||
|
<td><?php echo $company_data['source_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>company_source_id:</td>
|
||||||
|
<td><?php echo $company_data['company_source_id'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>company_source_id2:</td>
|
||||||
|
<td><?php echo $company_data['company_source_id2'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>company_name:</td>
|
||||||
|
<td><?php echo $company_data['company_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>company_state:</td>
|
||||||
|
<td><?php echo $company_data['company_state'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>company_create_timestamp:</td>
|
||||||
|
<td><?php echo $company_data['company_create_timestamp'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>company_modified_timestamp:</td>
|
||||||
|
<td><?php echo $company_data['company_modified_timestamp'] ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
128
pub/bin/pages/customers/pageCompanies_view.php
Normal file
128
pub/bin/pages/customers/pageCompanies_view.php
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_permissions.php');
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php';
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('customer-companies', 'RO', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['delete_confirmation'] = true;
|
||||||
|
$jsScriptLoadData['datatables'] = true;
|
||||||
|
$jsScriptLoadData['multiFilterSelect'] = true;
|
||||||
|
$jsScriptLoadData['datepicker'] = true;
|
||||||
|
$jsScriptLoadData['activateCompany'] = true;
|
||||||
|
# PageClasses Setup
|
||||||
|
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
if (!isset($_GET['all'])) {
|
||||||
|
$query = "SELECT companies.*, COUNT(servers.company_uuid) AS server_count FROM companies LEFT JOIN servers ON companies.company_uuid = servers.company_uuid WHERE company_state = 'active' GROUP BY companies.company_uuid ORDER BY companies.company_name ASC;";
|
||||||
|
} else {
|
||||||
|
$query = "SELECT companies.*, COUNT(servers.company_uuid) AS server_count FROM companies LEFT JOIN servers ON companies.company_uuid = servers.company_uuid GROUP BY companies.company_uuid ORDER BY companies.company_name ASC;";
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $GLOBALS['conn']->query($query);
|
||||||
|
$stompjes = array();
|
||||||
|
|
||||||
|
$companies = [];
|
||||||
|
while ($row = $stmt->fetch_assoc()) {
|
||||||
|
$companies[$row['company_uuid']] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row mb-3">
|
||||||
|
<div class="col-5">
|
||||||
|
<h2>
|
||||||
|
<i class="<?php echo $GLOBALS['pages']['customers']['companies']['page_icon'] ?>"></i> <?php echo __('companies') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div class="col d-flex justify-content-end px-1">
|
||||||
|
<div class="col-lg-auto col-md-auto col-sm-auto">
|
||||||
|
<?php
|
||||||
|
if (!isset($_GET['all'])) { ?>
|
||||||
|
<a class="btn btn-secondary" href="?all">
|
||||||
|
<i class="fa-solid fa-filter"></i> <?php echo __('show_all') ?>
|
||||||
|
</a>
|
||||||
|
<?php } else { ?>
|
||||||
|
<a class="btn btn-secondary" href="?">
|
||||||
|
<i class="fa-solid fa-filter"></i> <?php echo __('show_active') ?>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<form method="post" action="/api/v1/customers/companies/sync/">
|
||||||
|
<input type="hidden">
|
||||||
|
<div class="col-lg-auto col-md-auto col-sm-auto">
|
||||||
|
<button class="btn btn-primary">
|
||||||
|
<i class="fa-solid fa-arrow-rotate-right"></i> <?php echo __('sync') ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="multi-filter-select display table table-striped table-hover" data-skip-columns="0,1,2,4" data-page-length="50">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('company_name') ?></th>
|
||||||
|
<th><?php echo __('company_id') ?></th>
|
||||||
|
<th><?php echo __('company_debtor') ?></th>
|
||||||
|
<th><?php echo __('company_state') ?></th>
|
||||||
|
<th><?php echo __('server_count') ?></th>
|
||||||
|
<th><?php echo __('actions') ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('company_name') ?></th>
|
||||||
|
<th><?php echo __('company_id') ?></th>
|
||||||
|
<th><?php echo __('company_debtor') ?></th>
|
||||||
|
<th><?php echo __('company_state') ?></th>
|
||||||
|
<th><?php echo __('server_count') ?></th>
|
||||||
|
<th><?php echo __('actions') ?></th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
<?php foreach ($companies as $company) { ?>
|
||||||
|
<tr data-item-id="<?php echo $company['company_uuid'] ?>">
|
||||||
|
<td class="text-nowrap"><?php echo $company['company_name'] ?></td>
|
||||||
|
<td class="text-nowrap"><?php echo $company['company_source_id'] ?></td>
|
||||||
|
<td class="text-nowrap"><?php echo $company['company_source_id2'] ?></td>
|
||||||
|
<td class="text-nowrap"><?php echo $company['company_state'] ?></td>
|
||||||
|
<td class="text-nowrap"><?php echo $company['server_count'] ?></td>
|
||||||
|
<td>
|
||||||
|
<a href="/companies?view=<?php echo $company['company_uuid'] ?>" class="btn btn-info btn-sm btn-rounded" data-item-uuid="<?php echo $company['company_uuid'] ?>"><i class="fa-solid fa-eye"></i></a>
|
||||||
|
<?php if ($API->checkPermissions('customer-companies', 'RW', true) && $company['server_count'] == 0) { ?>
|
||||||
|
<a class="btn btn-<?php echo ($company['company_state'] != 'active') ? 'success' : 'danger' ?> btn-sm btn-rounded" data-item-company-state="" data-item-uuid="<?php echo $company['company_uuid'] ?>" data-item-state="<?php echo $company['company_state'] ?>"><i class="fa-solid <?php echo ($company['company_state'] != 'active') ? 'fa-plus' : 'fa-xmark' ?>"></i></a>
|
||||||
|
<?php } ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
190
pub/bin/pages/office/pageStompjes.php
Normal file
190
pub/bin/pages/office/pageStompjes.php
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_permissions.php');
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php';
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('ofice-stompjes', 'RO', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['delete_confirmation'] = true;
|
||||||
|
$jsScriptLoadData['stompjes'] = true;
|
||||||
|
$jsScriptLoadData['datatables'] = true;
|
||||||
|
$jsScriptLoadData['multiFilterSelect'] = true;
|
||||||
|
$jsScriptLoadData['datepicker'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$stmt = $GLOBALS['conn']->query("SELECT user_uuid, user_full_name, user_first_name, user_profile_picture_thumbnail, user_stompable, user_email FROM vc_users WHERE user_stompable = '1'");
|
||||||
|
$administrators = [];
|
||||||
|
while ($row = $stmt->fetch_assoc()) {
|
||||||
|
$administrators[$row['user_uuid']] = $row;
|
||||||
|
$administrators[$row['user_uuid']]['amount'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($_GET['fd'])) {
|
||||||
|
$SelectFromDate = strtotime(date('Y-m-01'));
|
||||||
|
} else {
|
||||||
|
$date = str_replace('/', '-', htmlspecialchars($_GET['fd'], ENT_QUOTES, 'UTF-8'));
|
||||||
|
$SelectFromDate = strtotime($date . ' 00:00:00');
|
||||||
|
}
|
||||||
|
if (!isset($_GET['td'])) {
|
||||||
|
$SelectTillDate = time();
|
||||||
|
} else {
|
||||||
|
$date = str_replace('/', '-', htmlspecialchars($_GET['td'], ENT_QUOTES, 'UTF-8'));
|
||||||
|
$SelectTillDate = strtotime($date . ' 23:59:59');
|
||||||
|
}
|
||||||
|
|
||||||
|
$stompjes = array();
|
||||||
|
$stmt = $GLOBALS['conn']->query("SELECT stomp_uuid, office_stompjes.user_uuid, user_full_name, user_first_name, stomp_timestamp FROM office_stompjes
|
||||||
|
INNER JOIN vc_users ON office_stompjes.user_uuid = vc_users.user_uuid
|
||||||
|
WHERE stomp_timestamp BETWEEN '$SelectFromDate' AND '$SelectTillDate'
|
||||||
|
AND user_stompable = '1'
|
||||||
|
ORDER BY stomp_timestamp DESC");
|
||||||
|
while ($row = $stmt->fetch_assoc()) {
|
||||||
|
array_push($stompjes, $row);
|
||||||
|
$administrators[$row['user_uuid']]['amount']++;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
?>
|
||||||
|
<script>
|
||||||
|
const stompData = <?php echo json_encode($stompjes); ?>;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row mb-3">
|
||||||
|
<div class="col-5">
|
||||||
|
<h2>
|
||||||
|
<i class="<?php echo $GLOBALS['pages']['office']['stompjeslist']['page_icon'] ?>"></i> <?php echo __('stompjeslist') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div class="col d-flex justify-content-end px-1">
|
||||||
|
<div class="col-lg-auto col-md-auto col-sm-auto mt-sm-1 px-1">
|
||||||
|
<label>
|
||||||
|
<h5><?php echo __('from') ?>: </h5>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-auto col-md-auto col-sm-auto">
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" id="fd" class="form-control" data-datepicker="true" value="<?php echo date('d/m/Y', $SelectFromDate) ?>"/>
|
||||||
|
<span class="input-group-text"><i class="fa fa-calendar-check"></i></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-auto col-md-auto col-sm-auto mt-sm-1 px-2">
|
||||||
|
<label>
|
||||||
|
<h5><?php echo __('to') ?>: </h5>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-auto col-md-auto col-sm-auto px-2">
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" id="td" class="form-control" data-datepicker="true" value="<?php echo date('d/m/Y', $SelectTillDate) ?>"/>
|
||||||
|
<span class="input-group-text"><i class="fa fa-calendar-check"></i></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-auto col-md-auto col-sm-auto">
|
||||||
|
<a id="datePicker" class="btn btn-primary"><i class="fa-solid fa-arrow-rotate-right"></i></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<canvas id="stompjesChart" height="50"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row align-content-center">
|
||||||
|
<?php foreach ($administrators as $administrator) {
|
||||||
|
if ($administrator['user_email'] != 'superuser') { ?>
|
||||||
|
<div class="col-sm-6 col-md-3 flex-shrink-0">
|
||||||
|
<div class="card card-stats card-round">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row align-items-center">
|
||||||
|
<div class="col-icon">
|
||||||
|
<div class="avatar-l">
|
||||||
|
<img class="avatar-img rounded-circle" src="data:image/png;base64,<?php echo str_replace("'", '', $administrator['user_profile_picture_thumbnail']) ?>" height="50px" alt="">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col col-stats ms-3 ms-sm-0">
|
||||||
|
<div class="numbers">
|
||||||
|
<p class="card-category"><?php echo $administrator['user_first_name'] ?></p>
|
||||||
|
<h4 class="card-title" id="count-<?php echo $administrator['user_uuid'] ?>"><?php echo $administrator['amount'] ?></h4>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col col-stats ms-3 ms-sm-0">
|
||||||
|
<a href="#" class="btn btn-warning btn-lg btn-rounded stomp-btn w-100 <?php echo (!$API->checkPermissions('ofice-stompjes-canstomp', 'RW', true)) ? 'disabled' : '' ?>" data-item-uuid="<?php echo $administrator['user_uuid'] ?>" data-item-name="user_uuid" data-api-url="/api/v1/office/stompjes/"><i class="fa-solid fa-hand-fist"></i></a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="multi-filter-select display table table-striped table-hover" data-skip-columns="0,2,3" data-page-length="50">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th><?php echo __('first_name') ?></th>
|
||||||
|
<th><?php echo __('time') ?></th>
|
||||||
|
<?php if ($API->checkPermissions('ofice-stompjes', 'RW', true)) { ?>
|
||||||
|
<th><?php echo __('actions') ?></th>
|
||||||
|
<?php } ?>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th><?php echo __('first_name') ?></th>
|
||||||
|
<th><?php echo __('time') ?></th>
|
||||||
|
<?php if ($API->checkPermissions('ofice-stompjes', 'RW', true)) { ?>
|
||||||
|
<th><?php echo __('actions') ?></th>
|
||||||
|
<?php } ?>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($stompjes as $stompje) {
|
||||||
|
if ($administrators[$stompje['user_uuid']]['user_email'] != 'superuser') { ?>
|
||||||
|
<tr data-item-id="<?php echo $stompje['stomp_uuid']; ?>" data-user-uuid=<?php echo $stompje['user_uuid']; ?>>
|
||||||
|
<td class="text-nowrap">
|
||||||
|
<div class="avatar-sm ">
|
||||||
|
<img class="avatar-img rounded-circle" src="data:image/png;base64,<?php echo str_replace("'", '', $administrators[$stompje['user_uuid']]['user_profile_picture_thumbnail']) ?>" height="50px" alt="">
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="text-nowrap"><?php echo $administrators[$stompje['user_uuid']]['user_first_name'] ?></td>
|
||||||
|
<td class="text-nowrap"><?php echo date('d-m-y H:i:s', $stompje['stomp_timestamp']) ?></td>
|
||||||
|
<?php if ($API->checkPermissions('ofice-stompjes', 'RW', true)) { ?>
|
||||||
|
<td>
|
||||||
|
<a href="#" class="btn btn-danger btn-sm btn-rounded stomp-delete-btn" data-item-uuid="<?php echo $stompje['stomp_uuid'] ?>" data-api-url="/api/v1/office/stompjes/" data-item-name="stomp_uuid"><i class="fas fa-trash-alt"></i></a>
|
||||||
|
</td>
|
||||||
|
<?php } ?>
|
||||||
|
</tr>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
77
pub/bin/pages/pageChangelog.php
Normal file
77
pub/bin/pages/pageChangelog.php
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<div class="card my-0">
|
||||||
|
<div class="card-body py-0 border">
|
||||||
|
<h5>
|
||||||
|
Sentri<br> Made by:
|
||||||
|
<a class="text-decoration-none" href="https://marcomooij.net" target="_blank">Marco Mooij</a><br> Version 1.0
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<h3>Version 1.0</h3>
|
||||||
|
<b>21-12-2025</b>
|
||||||
|
<h4>First release version</h4>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>First final release</b><br>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<h3>Version 0.1</h3>
|
||||||
|
<b>23-12-2024</b>
|
||||||
|
<h4>Initial release</h4>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>The start of this project</b><br>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<hr>
|
||||||
|
<h1>Roadmap</h1>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
View permissions in group view.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Translation in server view/overview.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Improvements into the server view.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Make the /login page the same style as the rest of Sentri.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Create a knowledge base.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
SSO/SAML/User provisioning.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
VM hosts overview.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Loggin of actions to local storage or to things such as graylog.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Light mode theme.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
View companies with connected servers.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
User email preferences.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Travel cost page.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Dashboard card display improvements.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Add descriptions to servers.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Add name to API tokens.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
If a server has the "new" state and it is deleted, it will be permanent.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
132
pub/bin/pages/pageDashboard.php
Normal file
132
pub/bin/pages/pageDashboard.php
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php';
|
||||||
|
$API = new API();
|
||||||
|
|
||||||
|
function showCard($module_name, $page_name, $width = 3)
|
||||||
|
{
|
||||||
|
$page = $GLOBALS['pages'][$module_name][$page_name];
|
||||||
|
?>
|
||||||
|
<div class="col-md-<?php echo $width ?> col-sm-6 ps-md-0 pb-3">
|
||||||
|
<a href="<?php echo $page['page_url'] ?>">
|
||||||
|
<div class="card-pricing2 card-<?php echo $page['page_color'] ?> text-center h-100">
|
||||||
|
<div class="pricing-header">
|
||||||
|
<h3 class="fw-bold mb-3 text-center"><?php echo __($page['page_name']) ?></h3>
|
||||||
|
</div>
|
||||||
|
<div class="price-value">
|
||||||
|
<div class="value ">
|
||||||
|
<span class="amount"><i class="text-<?php echo $page['page_color'] ?> <?php echo $page['page_icon'] ?> mt-4"></i><span></span></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-5">
|
||||||
|
<small>
|
||||||
|
<br>
|
||||||
|
<?php echo __($page['page_description']) ?>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="row mt-3">
|
||||||
|
<?php
|
||||||
|
if ($GLOBALS['modules_enabled']['customers'] && $API->checkPermissions('customer-companies', 'RO', true)) { ?>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="row ">
|
||||||
|
<div class="col-auto">
|
||||||
|
<h3><?php echo __('customers') ?></h3>
|
||||||
|
</div>
|
||||||
|
<div class="col mt-1">
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<?php
|
||||||
|
showCard('customers', 'companies', '6');
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
if ($GLOBALS['modules_enabled']['servers'] && $API->checkPermissions('servers', 'RO', true)) { ?>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-auto">
|
||||||
|
<h3><?php echo __('servers') ?></h3>
|
||||||
|
</div>
|
||||||
|
<div class="col mt-1">
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<?php
|
||||||
|
showCard('servers', 'server_overview', '6');
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($GLOBALS['modules_enabled']['office'] && $API->checkPermissions('ofice-stompjes', 'RO', true)) { ?>
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col-auto">
|
||||||
|
<h3><?php echo __('office') ?></h3>
|
||||||
|
</div>
|
||||||
|
<div class="col mt-1">
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<?php
|
||||||
|
showCard('office', 'stompjeslist');
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
|
||||||
|
if ($GLOBALS['modules_enabled']['autop']) { ?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-auto">
|
||||||
|
<h3><?php echo __('autoproviosioning') ?></h3>
|
||||||
|
</div>
|
||||||
|
<div class="col mt-1">
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row align-items-stretch">
|
||||||
|
<?php
|
||||||
|
showCard('autop', 'platforms');
|
||||||
|
showCard('autop', 'vendors');
|
||||||
|
showCard('autop', 'devices');
|
||||||
|
showCard('autop', 'device_settings');
|
||||||
|
showCard('autop', 'provisioning');
|
||||||
|
showCard('autop', 'phonebooks');
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($GLOBALS['modules_enabled']['system']) { ?>
|
||||||
|
<div class="row mt-3">
|
||||||
|
<div class="col-auto">
|
||||||
|
<h3><?php echo __('portal_management') ?></h3>
|
||||||
|
</div>
|
||||||
|
<div class="col mt-1">
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<?php
|
||||||
|
showCard('system', 'access_control');
|
||||||
|
showCard('system', 'systemconfig');
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
2
pub/bin/pages/pageNotFound.php
Normal file
2
pub/bin/pages/pageNotFound.php
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<?php
|
||||||
|
echo '404 not found';
|
||||||
9
pub/bin/pages/pageUserProfile.php
Normal file
9
pub/bin/pages/pageUserProfile.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (isset($_GET['edit'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/pageUserProfile_edit.php');
|
||||||
|
} else {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/pageUserProfile_view.php');
|
||||||
|
}
|
||||||
108
pub/bin/pages/pageUserProfile_edit.php
Normal file
108
pub/bin/pages/pageUserProfile_edit.php
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['Generatepassword'] = true;
|
||||||
|
$jsScriptLoadData['passwordShowHide'] = true;
|
||||||
|
$jsScriptLoadData['passwordRegen'] = true;
|
||||||
|
$jsScriptLoadData['enableButtonOnImageUpload'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$formBuilder = new formBuilder('Edit profile', '<i class="fas fa-plus"></i>', '/userprofile/');
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$user_groups_data = $GLOBALS['conn']->query("SELECT * FROM vc_user_groups WHERE user_group_type = 'admin' ORDER BY user_group_weight DESC");
|
||||||
|
$user_groups = array();
|
||||||
|
$user_data = false;
|
||||||
|
while ($user_group = $user_groups_data->fetch_assoc()) {
|
||||||
|
array_push($user_groups, $user_group);
|
||||||
|
$last_weight = $user_group['user_group_weight'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_uuid = $_SESSION['user']['user_uuid'];
|
||||||
|
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM vc_users INNER JOIN vc_user_groups ON vc_users.user_group_uuid = vc_user_groups.user_group_uuid WHERE user_uuid = ?");
|
||||||
|
$stmt->bind_param("s", $user_uuid);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
if ($result->num_rows == 1) {
|
||||||
|
$user_data = $result->fetch_assoc();
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('user_profile'), 'href' => '/userprofile/'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('edit'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
|
||||||
|
if ($user_data) {
|
||||||
|
$formBuilder->startForm(); ?>
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/users/">
|
||||||
|
<input type="hidden" name="user_uuid" value="<?php echo $user_uuid; ?>"/>
|
||||||
|
<div class="card-body">
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_email" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_email') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="email" class="form-control" id="user_email" name="user_email" value="<?php echo $user_data['user_email'] ?>" placeholder="user@example.xxx" required autofill="off" autocomplete="off"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_first_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('first_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_first_name" name="user_first_name" value="<?php echo $user_data['user_first_name'] ?>" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Last Name -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_last_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('last_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_last_name" name="user_last_name" value="<?php echo $user_data['user_last_name'] ?>" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Phone Number -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_phone_number" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('phone_number') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_phone_number" name="user_phone_number" placeholder="+1234542069" value="<?php echo $user_data['user_phone_number'] ?>"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Preferred Language -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_pref_language" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('preferred_language') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<select id="user_pref_language" name="user_pref_language" class="form-control">
|
||||||
|
<?php foreach (scandir($_SERVER['DOCUMENT_ROOT'] . '/bin/locales/') as $file) {
|
||||||
|
if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
|
||||||
|
$language = str_replace('.php', '', $file); ?>
|
||||||
|
<option <?php echo(($user_data['user_pref_language'] == $language) ? 'selected' : '') ?> value="<?php echo $language ?>"><?php echo __($language) ?></option>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $formBuilder->formFooter(); ?>
|
||||||
|
</form>
|
||||||
|
<?php $formBuilder->endForm(); ?><?php } else { ?>
|
||||||
|
<p>no admin with this uuid found.</p>
|
||||||
|
<?php } ?>
|
||||||
332
pub/bin/pages/pageUserProfile_view.php
Normal file
332
pub/bin/pages/pageUserProfile_view.php
Normal file
@@ -0,0 +1,332 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API_apitoken;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_apitoken.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['enableButtonOnImageUpload'] = true;
|
||||||
|
$jsScriptLoadData['delete_confirmation'] = true;
|
||||||
|
$jsScriptLoadData['CopyTargetData'] = true;
|
||||||
|
$jsScriptLoadData['updateToggle'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(false, '<i class="fa-solid fa-address-card"></i> ' . $_SESSION['user']['user_full_name'] . ' ' . strtolower(__('user_profile')));
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$user_groups_data = $GLOBALS['conn']->query("SELECT * FROM vc_user_groups WHERE user_group_type = 'admin' ORDER BY user_group_weight DESC");
|
||||||
|
$user_groups = array();
|
||||||
|
$admin_data = false;
|
||||||
|
while ($user_group = $user_groups_data->fetch_assoc()) {
|
||||||
|
array_push($user_groups, $user_group);
|
||||||
|
$last_weight = $user_group['user_group_weight'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_uuid = $_SESSION['user']['user_uuid'];
|
||||||
|
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM vc_users INNER JOIN vc_user_groups ON vc_users.user_group_uuid = vc_user_groups.user_group_uuid WHERE user_uuid = ?");
|
||||||
|
$stmt->bind_param("s", $user_uuid);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
if ($result->num_rows == 1) {
|
||||||
|
$user_data = $result->fetch_assoc();
|
||||||
|
}
|
||||||
|
|
||||||
|
$_GET['user_uuid'] = $user_uuid;
|
||||||
|
|
||||||
|
$requiredFields = ['user_uuid' => ['type' => 'uuid']];
|
||||||
|
$API_token = new API_apitoken();
|
||||||
|
$API_token->validateData($requiredFields);
|
||||||
|
$apitokens = $API_token->getTokens();
|
||||||
|
|
||||||
|
$new_api_token = false;
|
||||||
|
if (isset($_SESSION['tmp_api_token'])) {
|
||||||
|
$new_api_token = $_SESSION['tmp_api_token'];
|
||||||
|
unset($_SESSION['tmp_api_token']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($API_token->checkPermissions('admin-access-admins', 'RW', true)) {
|
||||||
|
$pageNavbar->AddHTMLButton('<a class="btn btn-primary mx-3" type="button" href="?edit=' . $_SESSION['user']['user_uuid'] . '"><i class="fas fa-edit"></i> ' . __('edit') . '</a>');
|
||||||
|
};
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
|
||||||
|
if ($user_data) { ?>
|
||||||
|
<div class="row d-flex align-items-stretch pb-2">
|
||||||
|
<div class="col-md-4 pb-4">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<form method="POST" action="/api/v1/users/avatar/" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="user_uuid" value="<?php echo $user_data['user_uuid'] ?>">
|
||||||
|
<h1 class="text-center"><?php echo $user_data['user_full_name'] ?></h1>
|
||||||
|
<div class="form-group form-show-validation row align-items-center justify-content-center">
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-file input-file-image">
|
||||||
|
<img class="img-upload-preview w-100" src="<?php echo(($user_data['user_profile_picture'] != null) ? 'data:image/png;base64, ' . $user_data['user_profile_picture'] : '/src/images/user-avatar-default-small.png') ?>" alt="user_profile_picture">
|
||||||
|
<input type="file" class="form-control form-control-file" id="user_profile_picture" name="user_profile_picture" accept="image/png" data-enable-button="user_profile_change">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group form-show-validation row justify-content-center">
|
||||||
|
<div class="d-flex flex-column align-items-center">
|
||||||
|
<label for="user_profile_picture" class="label-input-file btn btn-black btn-round mb-4">
|
||||||
|
<span class="btn-label"><i class="fa fa-file-image"></i></span>
|
||||||
|
<?php echo __('upload_image') ?>
|
||||||
|
</label>
|
||||||
|
<button id="user_profile_change" type="submit" class="btn btn-primary opacity-0 transition-opacity" disabled>
|
||||||
|
<i class="fa-solid fa-floppy-disk"></i> <?php echo __('save') ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8 pb-4">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>user_uuid:</td>
|
||||||
|
<td><?php echo $user_data['user_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_group_uuid:</td>
|
||||||
|
<td><?php echo $user_data['user_group_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_group_name:</td>
|
||||||
|
<td><?php echo $user_data['user_group_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_group_slugify:</td>
|
||||||
|
<td><?php echo $user_data['user_group_slugify'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_email:</td>
|
||||||
|
<td><?php echo $user_data['user_email'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_first_name:</td>
|
||||||
|
<td><?php echo $user_data['user_first_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_last_name:</td>
|
||||||
|
<td><?php echo $user_data['user_last_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_full_name:</td>
|
||||||
|
<td><?php echo $user_data['user_full_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_phone_number: </td>
|
||||||
|
<td><?php echo $user_data['user_phone_number'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_status: </td>
|
||||||
|
<td><?php echo $user_data['user_status'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_password_reset_expires: </td>
|
||||||
|
<td><?php echo $user_data['user_password_reset_expires'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_two_factor_enabled: </td>
|
||||||
|
<td><?php echo $user_data['user_two_factor_enabled'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_verified_email: </td>
|
||||||
|
<td><?php echo $user_data['user_verified_email'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_verified_phone: </td>
|
||||||
|
<td><?php echo $user_data['user_verified_phone'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_create_timestamp: </td>
|
||||||
|
<td><?php showTime($user_data['user_create_timestamp']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_modified_timestamp: </td>
|
||||||
|
<td><?php showTime($user_data['user_modified_timestamp']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_last_login_timestamp: </td>
|
||||||
|
<td><?php showTime($user_data['user_last_login_timestamp']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_login_attempts: </td>
|
||||||
|
<td><?php echo $user_data['user_login_attempts'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_pref_language: </td>
|
||||||
|
<td><?php echo $user_data['user_pref_language'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php if ($GLOBALS['modules_enabled']['office']) { ?>
|
||||||
|
<tr>
|
||||||
|
<td>user_stompable: </td>
|
||||||
|
<td><?php echo $user_data['user_stompable'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header pt-2 pb-1">
|
||||||
|
<h4>Email setttings</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
to be made later
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header pt-2 pb-1">
|
||||||
|
<h4><?php echo __('user_management') ?></h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div id="mfa-enabled-row" class="row" style="display: <?php echo(($_SESSION['user']['user_two_factor_enabled'] == 1) ? '' : 'none') ?>">
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="#" class="btn btn-danger delete-btn" data-item-uuid="<?php echo $user_uuid ?>" data-api-url="/api/v1/users/mfa/" data-delete-action='{"mfa-enabled-row":"hide", "mfa-disabled-row":"show"}' data-item-name='user_uuid'>
|
||||||
|
<i class="fa-solid fa-lock"></i> <?php echo __('reset_mfa') ?>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="mfa-disabled-row" class="row" style="display: <?php echo(($_SESSION['user']['user_two_factor_enabled'] == 1) ? 'none' : '') ?>">
|
||||||
|
<div class="col-auto">
|
||||||
|
<a class="btn btn-primary" href="/login/mfaSetup.php">
|
||||||
|
<i class="fa-solid fa-lock"></i> <?php echo __('set_mfa') ?>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-auto">
|
||||||
|
<a class="btn btn-primary mt-2" href="/login/resetPassword.php" disabled="">
|
||||||
|
<i class="fa-solid fa-lock"></i> <?php echo __('reset_password') ?>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header pt-2 pb-1">
|
||||||
|
<h4 class="mb-0">User history</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
To be made. Its going show the history of the user.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($API_token->checkPermissions('user-apitoken-self', 'RO', true)) { ?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<?php if ($new_api_token) { ?>
|
||||||
|
<div class="card bg-primary text-center">
|
||||||
|
<div class="card-body">
|
||||||
|
<h4><?php echo __('api_token_created') ?>!</h4>
|
||||||
|
<p>This token will be visible only now, please copy it now if you ever want to use it: </p>
|
||||||
|
<div class="d-flex justify-content-center align-items-center gap-2">
|
||||||
|
<div id="new-api-token" class="text-break" data-copy-data="<?php echo $new_api_token ?>">
|
||||||
|
<?php echo $new_api_token ?>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-dark" data-copy-target="new-api-token" title="Copy Token">
|
||||||
|
<i class="fa-solid fa-copy"></i> Copy
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header d-flex justify-content-between align-items-center pt-2 pb-1">
|
||||||
|
<h4 class="mb-0"><?php echo __('api_tokens') ?></h4>
|
||||||
|
<?php if ($API_token->checkPermissions('user-apitoken-self', 'RW', true)) { ?>
|
||||||
|
<form method="POST" action="/api/v1/users/apitoken/">
|
||||||
|
<input type="hidden" name="user_uuid" value="<?php echo $user_uuid ?>">
|
||||||
|
<input type="hidden" name="_return" value="/userprofile/">
|
||||||
|
<button type="submit" href="#" class="btn btn-primary">
|
||||||
|
<i class="fa-solid fa-plus"></i> <?php echo __('generate_new_api_token') ?>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<table class="table table-hover table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Token id</th>
|
||||||
|
<th>Expiration</th>
|
||||||
|
<th>Created</th>
|
||||||
|
<th>Last used</th>
|
||||||
|
<th>Revoked</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($apitokens as $token_data) { ?>
|
||||||
|
<tr>
|
||||||
|
<td class="text-nowrap" style="max-width: 100%;">
|
||||||
|
<div class="d-flex align-items-center gap-2" style="max-width: 100%;">
|
||||||
|
<div class="text-truncate" style="max-width: 200px;" id="<?php echo $token_data['api_token_uuid'] ?>" data-copy-data="<?php echo $token_data['api_token_uuid']; ?>">
|
||||||
|
<?php echo $token_data['api_token_uuid']; ?>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-secondary" data-copy-target="<?php echo $token_data['api_token_uuid'] ?>" title="Copy Token">
|
||||||
|
<i class="fa-solid fa-copy"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td><?php showTime($token_data['api_token_expiration_timestamp']) ?></td>
|
||||||
|
<td><?php showTime($token_data['api_token_created_timestamp']) ?></td>
|
||||||
|
<td><?php showTime($token_data['api_token_last_used_timestamp']) ?></td>
|
||||||
|
<td>
|
||||||
|
<label class="switch">
|
||||||
|
<input type="checkbox" class="checkbox" data-api-data='<?php echo json_encode(['api_token_uuid' => $token_data['api_token_uuid'], 'api_token_revoked' => $token_data['api_token_revoked'] ? 1 : 0]) ?>' data-api-changevalue="api_token_revoked" data-api-url="/api/v1/users/apitoken/" <?php echo((($token_data['api_token_revoked'])) ? 'checked' : '') ?>>
|
||||||
|
<div class="slider"></div>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
<?php if ($API_token->checkPermissions('user-apitoken-self', 'RW', true)) { ?>
|
||||||
|
<td class="text-nowrap">
|
||||||
|
<a href="#" class="btn btn-danger btn-sm btn-rounded delete-btn" data-item-uuid="<?php echo $token_data['api_token_uuid'] ?>" data-item-name="api_token_uuid" data-api-url="/api/v1/users/apitoken/"><i class="fas fa-trash-alt"></i></a>
|
||||||
|
</td>
|
||||||
|
<?php } ?>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?><?php } else {
|
||||||
|
echo 'user not found';
|
||||||
|
}
|
||||||
9
pub/bin/pages/servers/pageServerOverview.php
Normal file
9
pub/bin/pages/servers/pageServerOverview.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (isset($_GET['view'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/servers/pageServerOverview_server_view.php');
|
||||||
|
} else {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/servers/pageServerOverview_view.php');
|
||||||
|
}
|
||||||
415
pub/bin/pages/servers/pageServerOverview_server_view.php
Normal file
415
pub/bin/pages/servers/pageServerOverview_server_view.php
Normal file
@@ -0,0 +1,415 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php';
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('servers', 'RO', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['delete_confirmation'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$server_uuid = htmlspecialchars($_GET['view'], ENT_QUOTES, 'UTF-8');
|
||||||
|
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM servers WHERE server_uuid = ?");
|
||||||
|
$stmt->bind_param('s', $server_uuid);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
$server_data = $result->fetch_assoc();
|
||||||
|
|
||||||
|
$companies_data = $GLOBALS['conn']->query("SELECT company_uuid, company_name FROM companies WHERE company_state = 'active'");
|
||||||
|
$companies = array();
|
||||||
|
while ($company_data = $companies_data->fetch_assoc()) {
|
||||||
|
array_push($companies, $company_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$user_groups_data = $GLOBALS['conn']->query("SELECT * FROM vc_user_groups WHERE user_group_type = 'admin' ORDER BY user_group_weight DESC");
|
||||||
|
|
||||||
|
|
||||||
|
# memory
|
||||||
|
$mem = isset($server_data['server_memory']) ? (float)$server_data['server_memory'] : 0;
|
||||||
|
$demand = isset($server_data['server_memory_demand']) ? (float)$server_data['server_memory_demand'] : 0;
|
||||||
|
if ($mem > 0) {
|
||||||
|
$mem_percent = ($demand / $mem) * 100;
|
||||||
|
$mem_percent_numb = round($mem_percent, 1);
|
||||||
|
$mem_demand = round($mem_percent, 1) . "%"; // round to 1 decimal place
|
||||||
|
$mem_percent_sort = $mem_percent_numb;
|
||||||
|
|
||||||
|
if ($mem_percent_numb <= 89) {
|
||||||
|
$mem_demand_text_color = 'success';
|
||||||
|
}
|
||||||
|
if ($mem_percent_numb > 89) {
|
||||||
|
$mem_demand_text_color = 'secondary';
|
||||||
|
}
|
||||||
|
if ($mem_percent_numb > 99) {
|
||||||
|
$mem_demand_text_color = 'danger';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$mem_demand = "N/A";
|
||||||
|
$mem_percent_numb = 'N/A';
|
||||||
|
$mem_percent_sort = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
# disks
|
||||||
|
$disks = json_decode($server_data['server_disks'], true);
|
||||||
|
$totalDiskSpace = 0;
|
||||||
|
if (is_array($disks)) {
|
||||||
|
foreach ($disks as $disk) {
|
||||||
|
$totalDiskSpace += $disk['disk_space'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($disks) && count($disks) > 0) {
|
||||||
|
$sizes = array_column($disks, 'disk_space');
|
||||||
|
$totalDiskSpace = array_sum($sizes);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Licences
|
||||||
|
$licenses = json_decode($server_data['server_licenses'], true);
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
# OS Logo display
|
||||||
|
$baseos = strtolower(explode(' ', $server_data['server_os'])[0]);
|
||||||
|
$logos = [
|
||||||
|
'almalinux' => 'almalinux',
|
||||||
|
'centos' => 'centos',
|
||||||
|
];
|
||||||
|
$logo = $logos[$baseos] ?? 'server';
|
||||||
|
|
||||||
|
if ($API->checkPermissions('servers', 'RW', true)) {
|
||||||
|
$pageNavbar->AddHTMLButton(
|
||||||
|
'<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/servers/">
|
||||||
|
<input type="hidden" name="_method" value="POST">
|
||||||
|
<input type="hidden" name="_return" value="/servers?view=' . $server_data['server_uuid'] . '">
|
||||||
|
<input type="hidden" name="server_vm_id" value="' . $server_data['server_vm_id'] . '"/>' .
|
||||||
|
(
|
||||||
|
$server_data['server_state'] != 'deleted'
|
||||||
|
? '<input type="hidden" name="server_state" value="deleted">
|
||||||
|
<button class="btn btn-danger w-100">
|
||||||
|
<i class="fas fa-trash-alt"></i> Delete
|
||||||
|
</button>'
|
||||||
|
: '<input type="hidden" name="server_state" value="disabled">
|
||||||
|
<button class="btn btn-primary w-100">
|
||||||
|
<i class="fa-solid fa-clock-rotate-left"></i> Restore
|
||||||
|
</button>'
|
||||||
|
) .
|
||||||
|
'</form>'
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('server_overview'), 'href' => '/servers/'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => $server_data['server_vm_host_name'], 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row">
|
||||||
|
<h1>
|
||||||
|
<i class="<?php echo $GLOBALS['pages']['servers']['server_overview']['page_icon'] ?>"> </i> <?php echo $server_data['server_vm_host_name'] ?>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="row pb-5">
|
||||||
|
<div class="col-md-3 col-lg-3">
|
||||||
|
<h2><?php echo $server_data['server_os'] ?></h2>
|
||||||
|
<img class="img-fluid os-logo" src="/src/images/os/<?php echo $logo ?>.svg">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-lg-auto col-md-auto">
|
||||||
|
<table class="table table-borderless">
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/servers/">
|
||||||
|
<input type="hidden" name="_method" value="POST">
|
||||||
|
<input type="hidden" name="_return" value="/servers?view=<?php echo $server_data['server_uuid'] ?>">
|
||||||
|
<input type="hidden" name="server_vm_id" value="<?php echo $server_data['server_vm_id'] ?>"/>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<h4>
|
||||||
|
<i class="fa-solid fa-microchip"></i> <?php echo __('server_cpu') ?>
|
||||||
|
</h4>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h4>
|
||||||
|
<?php echo (strlen($server_data['server_cpu']) > 0) ? $server_data['server_cpu'] . 'x' : ''; ?>
|
||||||
|
</h4>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<h4>
|
||||||
|
<i class="fa-solid fa-memory"></i> <?php echo __('server_memory') ?>
|
||||||
|
</h4>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h4>
|
||||||
|
<?php echo (strlen($server_data['server_memory']) > 0) ? $server_data['server_memory'] . 'MB' : ''; ?>
|
||||||
|
</h4>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<h4>
|
||||||
|
<i class="fa-solid fa-hard-drive"></i> <?php echo __('server_disks') ?>
|
||||||
|
</h4>
|
||||||
|
</td>
|
||||||
|
<td class="mx-3">
|
||||||
|
<h4>
|
||||||
|
<?php
|
||||||
|
if (is_array($disks) && count($disks) > 0) {
|
||||||
|
if (count($sizes) === 1) {
|
||||||
|
echo $sizes[0] . 'GB';
|
||||||
|
} else {
|
||||||
|
echo $totalDiskSpace . 'GB (' . implode('GB, ', $sizes) . 'GB)';
|
||||||
|
}
|
||||||
|
} ?>
|
||||||
|
</h4>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<h4>
|
||||||
|
<i class="fas fa-building"></i> <?php echo __('company') ?>
|
||||||
|
</h4>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php if ($API->checkPermissions('servers', 'RW', true)) { ?>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="input-group">
|
||||||
|
<select id="company_uuid" name="company_uuid" class="form-control">
|
||||||
|
<option></option>
|
||||||
|
<?php foreach ($companies as $company) { ?>
|
||||||
|
<option <?php echo ($server_data['company_uuid'] == $company['company_uuid']) ? 'selected' : '' ?> value="<?php echo $company['company_uuid'] ?>"><?php echo $company['company_name'] ?></option>
|
||||||
|
<?php } ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php } else { ?>
|
||||||
|
<h4>
|
||||||
|
<?php
|
||||||
|
$companyMap = array_column($companies, 'company_name', 'company_uuid');
|
||||||
|
echo $companyMap[$server_data['company_uuid']] ?? null;
|
||||||
|
?>
|
||||||
|
</h4>
|
||||||
|
<?php } ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<h4>
|
||||||
|
<i class="fa-solid fa-circle-dot"></i> <?php echo __('server_state') ?>
|
||||||
|
</h4>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php if ($API->checkPermissions('servers', 'RW', true)) {
|
||||||
|
if ($server_data['server_state'] != 'deleted') { ?>
|
||||||
|
<div class="input-group">
|
||||||
|
<select id="server_state" class="form-control" onchange="this.name = this.value ? 'server_state' : '';">
|
||||||
|
<option></option>
|
||||||
|
<option <?php echo ($server_data['server_state'] == 'active') ? 'selected' : '' ?> value="active">Active</option>
|
||||||
|
<option <?php echo ($server_data['server_state'] == 'trial') ? 'selected' : '' ?> value="trial">Trial</option>
|
||||||
|
<option <?php echo ($server_data['server_state'] == 'disabled') ? 'selected' : '' ?> value="disabled">Disabled</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php } else { ?>
|
||||||
|
<h4>
|
||||||
|
<?php echo ucfirst($server_data['server_state']) ?>
|
||||||
|
</h4>
|
||||||
|
<?php }
|
||||||
|
} else { ?>
|
||||||
|
<h4>
|
||||||
|
<?php echo ucfirst($server_data['server_state']) ?>
|
||||||
|
</h4>
|
||||||
|
<?php } ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<h4>
|
||||||
|
<i class="fa-regular fa-clock"></i> <?php echo __('last_update') ?>
|
||||||
|
</h4>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<h4>
|
||||||
|
<?php echo date('Y-m-d H:i:s', $server_data['server_modified_timestamp']) ?>
|
||||||
|
</h4>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
if ($API->checkPermissions('servers', 'RW', true)) { ?>
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-rounded btn-success w-100">
|
||||||
|
<i class="fa-solid fa-floppy-disk"></i> <?php echo __('save') ?>
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</form>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if (is_array($disks) && count($disks) > 0) { ?>
|
||||||
|
<h2>
|
||||||
|
<i class="fa-solid fa-hard-drive"></i> <?php echo __('server_disks') ?>
|
||||||
|
</h2>
|
||||||
|
<div id="accordion">
|
||||||
|
<div class="card">
|
||||||
|
<?php foreach ($disks as $disk) { ?>
|
||||||
|
<a data-bs-toggle="collapse" data-bs-target="#collapse<?php echo $disk['disk_name'] ?>">
|
||||||
|
<div class="card-header py-1" id="heading<?php echo $disk['disk_name'] ?>">
|
||||||
|
<h4 class="mb-0 text-success">
|
||||||
|
<i class="fa-solid fa-hard-drive"></i> <?php echo $disk['disk_name'] ?>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div id="collapse<?php echo $disk['disk_name'] ?>" class="collapse" data-parent="#accordion">
|
||||||
|
<div class="card-body">
|
||||||
|
<?php echo __('disk_space') ?>: <?php echo $disk['disk_space'] ?>
|
||||||
|
<br> <?php echo __('disk_used') ?>: <?php echo $disk['disk_used'] ?>
|
||||||
|
<br> <?php echo __('disk_location') ?>: <?php echo $disk['disk_location'] ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
} ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
|
||||||
|
|
||||||
|
if (is_array($licenses) && count($licenses) > 0) { ?>
|
||||||
|
<h2>
|
||||||
|
<i class="fa-solid fa-file-invoice-dollar"></i> <?php echo __('server_licenses') ?>
|
||||||
|
</h2>
|
||||||
|
<div id="accordion">
|
||||||
|
<div class="card">
|
||||||
|
<?php foreach ($licenses as $key => $licence) { ?>
|
||||||
|
<a data-bs-toggle="collapse" data-bs-target="#collapse<?php echo array_key_first($licence) ?>">
|
||||||
|
<div class="card-header py-1" id="heading<?php echo array_key_first($licence) ?>">
|
||||||
|
<h4 class="mb-0 text-success">
|
||||||
|
<i class="fa-solid fa-file-invoice-dollar"></i> <?php echo array_key_first($licence) ?>
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div id="collapse<?php echo array_key_first($licence) ?>" class="collapse" data-parent="#accordion">
|
||||||
|
<div class="card-body">
|
||||||
|
<?php echo __('type') . ': ' . end($licence) ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
} ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<h1 class="pt-5"><?php echo __('all_technical_information') ?></h1>
|
||||||
|
<div class="col-md-6 col-lg-6">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>server_uuid:</td>
|
||||||
|
<td><?php echo $server_data['server_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>company_uuid:</td>
|
||||||
|
<td><?php echo $server_data['company_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_vm_id:</td>
|
||||||
|
<td><?php echo $server_data['server_vm_id'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_vm_host_name:</td>
|
||||||
|
<td><?php echo $server_data['server_vm_host_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_power_state:</td>
|
||||||
|
<td><?php echo $server_data['server_power_state'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_hostname:</td>
|
||||||
|
<td><?php echo $server_data['server_hostname'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_os:</td>
|
||||||
|
<td><?php echo $server_data['server_os'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_cpu:</td>
|
||||||
|
<td><?php echo $server_data['server_cpu'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_memory:</td>
|
||||||
|
<td><?php echo $server_data['server_memory'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_memory_demand:</td>
|
||||||
|
<td><?php echo $server_data['server_memory_demand'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_disks:</td>
|
||||||
|
<td><?php echo $server_data['server_disks'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_ipv4:</td>
|
||||||
|
<td><?php echo $server_data['server_ipv4'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_ipv6:</td>
|
||||||
|
<td><?php echo $server_data['server_ipv6'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_licenses:</td>
|
||||||
|
<td><?php echo $server_data['server_licenses'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_backup:</td>
|
||||||
|
<td><?php echo $server_data['server_backup'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_description:</td>
|
||||||
|
<td><?php echo $server_data['server_description'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_create_timestamp:</td>
|
||||||
|
<td><?php echo $server_data['server_create_timestamp'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>server_modified_timestamp:</td>
|
||||||
|
<td><?php echo $server_data['server_modified_timestamp'] ?></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
503
pub/bin/pages/servers/pageServerOverview_view.php
Normal file
503
pub/bin/pages/servers/pageServerOverview_view.php
Normal file
@@ -0,0 +1,503 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php';
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('servers', 'RO', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['delete_confirmation'] = true;
|
||||||
|
$jsScriptLoadData['datatables'] = true;
|
||||||
|
$jsScriptLoadData['multiFilterSelectServers'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
if (!isset($_GET['del'])) {
|
||||||
|
$query = "SELECT * FROM servers LEFT JOIN companies ON companies.company_uuid = servers.company_uuid WHERE servers.server_state != 'deleted' ORDER BY server_vm_host_name";
|
||||||
|
} else {
|
||||||
|
$query = "SELECT * FROM servers LEFT JOIN companies ON companies.company_uuid = servers.company_uuid ORDER BY server_vm_host_name";
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $GLOBALS['conn']->query($query);
|
||||||
|
$servers = [];
|
||||||
|
while ($row = $stmt->fetch_assoc()) {
|
||||||
|
array_push($servers, $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
$allBackupTypes = [];
|
||||||
|
$allLicenseTypes = [];
|
||||||
|
foreach ($servers as $server) {
|
||||||
|
if (!empty($server['server_backup'])) {
|
||||||
|
$backups = json_decode($server['server_backup'], true);
|
||||||
|
if (is_array($backups)) {
|
||||||
|
foreach ($backups as $item) {
|
||||||
|
foreach ($item as $key => $value) {
|
||||||
|
$allBackupTypes[$key] = true; // use keys as unique types
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($server['server_licenses'])) {
|
||||||
|
$licenses = json_decode($server['server_licenses'], true);
|
||||||
|
if (is_array($licenses)) {
|
||||||
|
foreach ($licenses as $item) {
|
||||||
|
foreach ($item as $key => $value) {
|
||||||
|
$allLicenseTypes[$key] = true; // keys are license types
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
$allBackupTypes = array_keys($allBackupTypes);
|
||||||
|
sort($allBackupTypes);
|
||||||
|
|
||||||
|
$allLicenseTypes = array_keys($allLicenseTypes);
|
||||||
|
sort($allLicenseTypes);
|
||||||
|
|
||||||
|
$showColumns = array(
|
||||||
|
'server_hostname' => false,
|
||||||
|
'company_name' => false,
|
||||||
|
'server_power_state' => false,
|
||||||
|
'server_os' => false,
|
||||||
|
'server_cpu' => false,
|
||||||
|
'server_memory' => false,
|
||||||
|
'server_memory_demand' => false,
|
||||||
|
'server_disks' => false,
|
||||||
|
'server_ipv4' => false,
|
||||||
|
'server_ipv6' => false,
|
||||||
|
'server_vm_snapshot' => false,
|
||||||
|
'server_vm_generation' => false,
|
||||||
|
'server_licenses' => false,
|
||||||
|
'server_backup' => false,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset($_COOKIE['serverTableColumns'])) {
|
||||||
|
$CheckedColumns = json_decode(htmlspecialchars(($_COOKIE['serverTableColumns']), true));
|
||||||
|
foreach ($CheckedColumns as $CheckedColumn) {
|
||||||
|
$showColumns[$CheckedColumn] = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$showColumns['server_hostname'] = true;
|
||||||
|
$showColumns['company_name'] = true;
|
||||||
|
$showColumns['server_os'] = true;
|
||||||
|
$showColumns['server_cpu'] = true;
|
||||||
|
$showColumns['server_memory'] = true;
|
||||||
|
$showColumns['server_memory_demand'] = true;
|
||||||
|
$showColumns['server_disks'] = true;
|
||||||
|
$showColumns['server_state'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function cleanNumber($num)
|
||||||
|
{
|
||||||
|
// If integer value, return without formatting
|
||||||
|
if (floor($num) == $num) {
|
||||||
|
return (string)$num;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise return trimmed float
|
||||||
|
return rtrim(rtrim(number_format($num, 10, '.', ''), '0'), '.');
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('permission'), 'href' => '/accesscontrol/#permissions'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('view'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row mb-3">
|
||||||
|
<div class="col-auto">
|
||||||
|
<h2>
|
||||||
|
<i class="<?php echo $GLOBALS['pages']['servers']['server_overview']['page_icon'] ?>"></i> <?php echo __('server_overview') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div class="col d-flex justify-content-end px-1">
|
||||||
|
<div class="selectgroup selectgroup-pills">
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_state" class="selectgroup-input" <?php echo($showColumns['server_state'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_state') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_hostname" class="selectgroup-input" <?php echo($showColumns['server_hostname'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_hostname') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="company_name" class="selectgroup-input" <?php echo($showColumns['company_name'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('company') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_os" class="selectgroup-input" <?php echo($showColumns['server_os'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_os') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_cpu" class="selectgroup-input" <?php echo($showColumns['server_cpu'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_cpu') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_memory" class="selectgroup-input" <?php echo($showColumns['server_memory'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_memory') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_memory_demand" class="selectgroup-input" <?php echo($showColumns['server_memory_demand'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_memory_demand') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_disks" class="selectgroup-input" <?php echo($showColumns['server_disks'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_disks') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_ipv4" class="selectgroup-input" <?php echo($showColumns['server_ipv4'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_ipv4') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_ipv6" class="selectgroup-input" <?php echo($showColumns['server_ipv6'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_ipv6') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_vm_snapshot" class="selectgroup-input" <?php echo($showColumns['server_vm_snapshot'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_vm_snapshot') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_vm_generation" class="selectgroup-input" <?php echo($showColumns['server_vm_generation'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_vm_generation') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_licenses" class="selectgroup-input" <?php echo($showColumns['server_licenses'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_licenses') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_backup" class="selectgroup-input" <?php echo($showColumns['server_backup'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_backup') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_power_state" class="selectgroup-input" <?php echo($showColumns['server_power_state'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('server_power_state') ?></span>
|
||||||
|
</label>
|
||||||
|
<label class="selectgroup-item">
|
||||||
|
<input type="checkbox" name="value" value="server_description" class="selectgroup-input" <?php echo($showColumns['server_description'] ? 'checked=""' : '') ?>>
|
||||||
|
<span class="selectgroup-button"><?php echo __('description') ?></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-auto col-md-auto col-sm-auto">
|
||||||
|
<?php
|
||||||
|
if (!isset($_GET['del'])) { ?>
|
||||||
|
<a class="btn btn-danger btn-border" href="?del">
|
||||||
|
<i class="fa-solid fa-filter"></i> <?php echo __('show_del') ?>
|
||||||
|
</a>
|
||||||
|
<?php } else { ?>
|
||||||
|
<a class="btn btn-danger " href="/servers">
|
||||||
|
<i class="fa-solid fa-filter"></i> <?php echo __('show_del') ?>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="multi-filter-select display table table-striped table-hover" data-skip-columns="action" data-page-length="50">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-column="server_state"><?php echo __('server_state') ?></th>
|
||||||
|
<th data-column="server_hostname"><?php echo __('server_hostname') ?></th>
|
||||||
|
<th data-column="company_name"><?php echo __('company') ?></th>
|
||||||
|
<th data-column="server_os"><?php echo __('server_os') ?></th>
|
||||||
|
<th data-column="server_cpu">
|
||||||
|
<i class="fa-solid fa-microchip"></i> <?php echo __('server_cpu') ?>
|
||||||
|
</th>
|
||||||
|
<th data-column="server_memory">
|
||||||
|
<i class="fa-solid fa-memory"></i> <?php echo __('server_memory') ?>
|
||||||
|
</th>
|
||||||
|
<th data-column="server_memory_demand"><?php echo __('server_memory_demand') ?></th>
|
||||||
|
<th data-column="server_disks">
|
||||||
|
<i class="fa-solid fa-hard-drive"></i> <?php echo __('server_disks') ?>
|
||||||
|
</th>
|
||||||
|
<th data-column="server_ipv4">
|
||||||
|
<?php echo __('server_ipv4') ?>
|
||||||
|
</th>
|
||||||
|
<th data-column="server_ipv6">
|
||||||
|
<?php echo __('server_ipv6') ?>
|
||||||
|
</th>
|
||||||
|
<th data-column="server_vm_snapshot"><?php echo __('server_vm_snapshot') ?></th>
|
||||||
|
<th data-column="server_vm_generation"><?php echo __('server_vm_generation') ?></th>
|
||||||
|
<?php
|
||||||
|
foreach ($allLicenseTypes as $licenseType) { ?>
|
||||||
|
<th data-column="server_licenses_<?php echo $licenseType ?>"><?php echo $licenseType ?></th>
|
||||||
|
<?php }
|
||||||
|
foreach ($allBackupTypes as $backupType) { ?>
|
||||||
|
<th data-column="server_backup_<?php echo $backupType ?>"><?php echo $backupType ?></th>
|
||||||
|
<?php }
|
||||||
|
?>
|
||||||
|
<th data-column="server_power_state"><?php echo __('server_power_state') ?></th>
|
||||||
|
<th data-column="server_description"><?php echo __('description') ?></th>
|
||||||
|
<th data-column="action">
|
||||||
|
<?php echo __('action') ?>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th data-column="server_state"><?php echo __('server_state') ?></th>
|
||||||
|
<th data-column="server_hostname"><?php echo __('server_hostname') ?></th>
|
||||||
|
<th data-column="company_name"><?php echo __('company') ?></th>
|
||||||
|
<th data-column="server_os"><?php echo __('server_os') ?></th>
|
||||||
|
<th data-column="server_cpu"><?php echo __('server_cpu') ?></th>
|
||||||
|
<th data-column="server_memory"><?php echo __('server_memory') ?></th>
|
||||||
|
<th data-column="server_memory_demand"><?php echo __('server_memory_demand') ?></th>
|
||||||
|
<th data-column="server_disks"><?php echo __('server_disks') ?></th>
|
||||||
|
<th data-column="server_ipv4"><?php echo __('server_ipv4') ?></th>
|
||||||
|
<th data-column="server_ipv6"><?php echo __('server_ipv6') ?></th>
|
||||||
|
<th data-column="server_vm_snapshot"><?php echo __('server_vm_snapshot') ?></th>
|
||||||
|
<th data-column="server_vm_generation"><?php echo __('server_vm_generation') ?></th>
|
||||||
|
<?php
|
||||||
|
foreach ($allLicenseTypes as $licenseType) { ?>
|
||||||
|
<th data-column="server_licenses_<?php echo $licenseType ?>"><?php echo $licenseType ?></th>
|
||||||
|
<?php }
|
||||||
|
foreach ($allBackupTypes as $backupType) { ?>
|
||||||
|
<th data-column="server_backup_<?php echo $backupType ?>"><?php echo $backupType ?></th>
|
||||||
|
<?php }
|
||||||
|
?>
|
||||||
|
<th data-column="server_power_state"><?php echo __('server_power_state') ?></th>
|
||||||
|
<th data-column="server_description"><?php echo __('description') ?></th>
|
||||||
|
<th data-column="action"><?php echo __('action') ?></th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
foreach ($servers as $server) {
|
||||||
|
$disks = json_decode($server['server_disks'], true);
|
||||||
|
$totalDiskSpace = 0;
|
||||||
|
if (is_array($disks)) {
|
||||||
|
foreach ($disks as $disk) {
|
||||||
|
$totalDiskSpace += $disk['disk_space'];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($server['server_vm_host_name'])) {
|
||||||
|
$hostname = $server['server_hostname'];
|
||||||
|
} else {
|
||||||
|
$hostname = $server['server_vm_host_name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$mem = isset($server['server_memory']) ? (float)$server['server_memory'] : 0;
|
||||||
|
$demand = isset($server['server_memory_demand']) ? (float)$server['server_memory_demand'] : 0;
|
||||||
|
|
||||||
|
if ($mem == 0 && $demand == 0) {
|
||||||
|
$mem_assigned = 'N/A';
|
||||||
|
} else {
|
||||||
|
$mem_assigned = cleanNumber($mem) . "M";
|
||||||
|
}
|
||||||
|
|
||||||
|
$mem_demand_text_color = '';
|
||||||
|
if ($mem > 0) {
|
||||||
|
$mem_percent = ($demand / $mem) * 100;
|
||||||
|
$mem_percent_numb = round($mem_percent, 1);
|
||||||
|
$mem_demand = round($mem_percent, 1) . "%"; // round to 1 decimal place
|
||||||
|
$mem_percent_sort = $mem_percent_numb;
|
||||||
|
|
||||||
|
if ($mem_percent_numb <= 89) {
|
||||||
|
$mem_demand_text_color = 'success';
|
||||||
|
}
|
||||||
|
if ($mem_percent_numb > 89) {
|
||||||
|
$mem_demand_text_color = 'secondary';
|
||||||
|
}
|
||||||
|
if ($mem_percent_numb > 99) {
|
||||||
|
$mem_demand_text_color = 'danger';
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$mem_demand = "N/A";
|
||||||
|
$mem_percent_numb = 'N/A';
|
||||||
|
$mem_percent_sort = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ipv4_list = '';
|
||||||
|
if (!empty($server['server_ipv4'])) {
|
||||||
|
$ips = json_decode($server['server_ipv4'], true);
|
||||||
|
if (is_array($ips)) {
|
||||||
|
$ipv4_list = implode(', ', $ips);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ipv6_list = '';
|
||||||
|
if (!empty($server['server_ipv6'])) {
|
||||||
|
$ips = json_decode($server['server_ipv6'], true);
|
||||||
|
if (is_array($ips)) {
|
||||||
|
$ipv6_list = implode(', ', $ips);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$thisServerLicenses = [];
|
||||||
|
foreach ($allLicenseTypes as $licenseType) {
|
||||||
|
$thisServerLicenses[$licenseType] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($server['server_licenses'])) {
|
||||||
|
$allLicenseTypesServer = json_decode($server['server_licenses'], true);
|
||||||
|
if (is_array($allLicenseTypesServer)) {
|
||||||
|
foreach ($allLicenseTypesServer as $licenseTypeServer) {
|
||||||
|
foreach ($licenseTypeServer as $licenseTypeServerKey => $licenseTypeServerValue) {
|
||||||
|
$thisServerLicenses[$licenseTypeServerKey] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$thisServerBackup = [];
|
||||||
|
foreach ($allBackupTypes as $BackupType) {
|
||||||
|
$thisServerBackup[$BackupType] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($server['server_backup'])) {
|
||||||
|
$allBackupTypesServer = json_decode($server['server_backup'], true);
|
||||||
|
if (is_array($allBackupTypesServer)) {
|
||||||
|
foreach ($allBackupTypesServer as $BackupTypeServer) {
|
||||||
|
foreach ($BackupTypeServer as $BackupTypeServerKey => $BackupTypeServerValue) {
|
||||||
|
$thisServerBackup[$BackupTypeServerKey] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$company_name = '';
|
||||||
|
if (strlen($server['company_name']) > 0) {
|
||||||
|
$company_name = $server['company_name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$server_state_color = 'secondary';
|
||||||
|
if (strlen($server['server_state']) > 0) {
|
||||||
|
$server_state = ucfirst($server['server_state']);
|
||||||
|
switch ($server_state) {
|
||||||
|
case 'New':
|
||||||
|
$server_state_color = 'secondary';
|
||||||
|
break;
|
||||||
|
case 'Deleted':
|
||||||
|
$server_state_color = 'danger';
|
||||||
|
break;
|
||||||
|
case 'Trial':
|
||||||
|
$server_state_color = 'primary';
|
||||||
|
break;
|
||||||
|
case 'Disabled':
|
||||||
|
$server_state_color = 'gray';
|
||||||
|
break;
|
||||||
|
case 'Active':
|
||||||
|
$server_state_color = 'success';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
<tr data-item-id="<?php echo $server['server_uuid'] ?>">
|
||||||
|
<td data-column="server_state" class="text-nowrap" data-filter="<?php echo htmlspecialchars($server_state); ?>" data-sort="<?php echo htmlspecialchars($server_state); ?>">
|
||||||
|
<span class="badge rounded-pill bg-<?php echo $server_state_color ?>"><?php echo $server_state ?></span>
|
||||||
|
</td>
|
||||||
|
<td data-column="server_hostname" class="text-nowrap" data-filter="<?php echo htmlspecialchars($hostname); ?>" data-sort="<?php echo htmlspecialchars($hostname); ?>">
|
||||||
|
<i class="fa-solid fa-server"></i> <?php echo $hostname ?>
|
||||||
|
</td>
|
||||||
|
<td data-column="company_name" class="text-nowrap" data-filter="<?php echo $company_name ?>" data-sort="<?php echo $company_name ?>">
|
||||||
|
<?php echo $company_name ?>
|
||||||
|
</td>
|
||||||
|
<td data-column="server_os" class="text-nowrap"><?php echo $server['server_os'] ?></td>
|
||||||
|
<td data-column="server_cpu" class="text-nowrap"><?php echo $server['server_cpu'] ?>
|
||||||
|
</td>
|
||||||
|
<td data-column="server_memory" class="text-nowrap" data-filter="<?php echo htmlspecialchars($mem); ?>" data-sort="<?php echo htmlspecialchars($mem); ?>">
|
||||||
|
<?php echo $mem_assigned ?>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-column="server_memory_demand" class="text-nowrap <?php echo 'text-' . $mem_demand_text_color ?>" data-filter="<?php echo htmlspecialchars($mem_percent_numb); ?>" data-sort="<?php echo htmlspecialchars($mem_percent_sort); ?>">
|
||||||
|
<?php echo $mem_demand ?>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td data-column="server_disks" class="text-nowrap"
|
||||||
|
<?php
|
||||||
|
$sortValue = '';
|
||||||
|
$filterValue = '';
|
||||||
|
|
||||||
|
if (is_array($disks) && count($disks) > 0) {
|
||||||
|
$sizes = array_column($disks, 'disk_space');
|
||||||
|
$totalDiskSpace = array_sum($sizes);
|
||||||
|
|
||||||
|
if ($totalDiskSpace > 0) {
|
||||||
|
$sortValue = $totalDiskSpace;
|
||||||
|
$filterValue = $totalDiskSpace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
data-sort="<?php echo htmlspecialchars($sortValue); ?>" data-filter="<?php echo htmlspecialchars($filterValue); ?>">
|
||||||
|
<?php
|
||||||
|
if (!empty($sortValue)) {
|
||||||
|
if (count($sizes) === 1) {
|
||||||
|
echo $sizes[0] . 'GB';
|
||||||
|
} else {
|
||||||
|
echo $totalDiskSpace . 'GB (' . implode('GB, ', $sizes) . 'GB)';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
|
<td data-column="server_ipv4" class="text-nowrap" data-sort="<?php echo htmlspecialchars($ipv4_list); ?>" data-filter="<?php echo htmlspecialchars($ipv4_list); ?>">
|
||||||
|
<?php echo $ipv4_list ?>
|
||||||
|
</td>
|
||||||
|
<td data-column="server_ipv6" class="text-nowrap" data-sort="<?php echo htmlspecialchars($ipv6_list); ?>" data-filter="<?php echo htmlspecialchars($ipv6_list); ?>">
|
||||||
|
<?php echo $ipv6_list ?>
|
||||||
|
</td>
|
||||||
|
<td data-column="server_vm_snapshot" class="text-nowrap" data-sort="<?php echo htmlspecialchars($server['server_vm_snapshot']); ?>" data-filter="<?php echo htmlspecialchars($server['server_vm_snapshot']); ?>">
|
||||||
|
<?php echo $server['server_vm_snapshot']; ?>
|
||||||
|
</td>
|
||||||
|
<td data-column="server_vm_generation" class="text-nowrap" data-sort="<?php echo htmlspecialchars($server['server_vm_generation']); ?>" data-filter="<?php echo htmlspecialchars($server['server_vm_generation']); ?>">
|
||||||
|
<?php echo $server['server_vm_generation']; ?>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
|
||||||
|
foreach ($allLicenseTypes as $licenseType) { ?>
|
||||||
|
<td data-column="server_license_<?php echo $licenseType ?>" class="text-nowrap" data-sort="<?php echo ($thisServerLicenses[$licenseType]) ? 'yes' : 'no' ?>" data-filter="<?php echo ($thisServerLicenses[$licenseType]) ? 'yes' : 'no' ?>"><?php echo ($thisServerLicenses[$licenseType]) ? '<i class="fa-solid text-success fa-toggle-on"></i>' : '<i class="fa-solid text-danger fa-toggle-off"></i>' ?></td>
|
||||||
|
<?php }
|
||||||
|
foreach ($allBackupTypes as $BackupType) { ?>
|
||||||
|
<td data-column="server_backup_<?php echo $BackupType ?>" class="text-nowrap" data-sort="<?php echo ($thisServerLicenses[$licenseType]) ? 'yes' : 'no' ?>" data-filter="<?php echo ($thisServerLicenses[$licenseType]) ? 'yes' : 'no' ?>"><?php echo ($thisServerBackup[$BackupType]) ? '<i class="fa-solid text-success fa-toggle-on"></i>' : '<i class="fa-solid text-danger fa-toggle-off"></i>' ?></td>
|
||||||
|
<?php }
|
||||||
|
?>
|
||||||
|
<td data-column="server_power_state" class="text-nowrap" data-filter="<?php echo htmlspecialchars($server['server_power_state']); ?>" data-sort="<?php echo htmlspecialchars($server['server_power_state']); ?>">
|
||||||
|
<?php
|
||||||
|
if ($server['server_power_state'] == 'Off') {
|
||||||
|
echo '<i class="fa-solid text-danger fa-toggle-off"></i>';
|
||||||
|
} elseif ($server['server_power_state'] == 'Running') {
|
||||||
|
echo '<i class="fa-solid text-success fa-toggle-on"></i>';
|
||||||
|
} ?>
|
||||||
|
</td>
|
||||||
|
<td data-column="server_description" class="text-nowrap" data-sort="<?php echo htmlspecialchars($server['server_description']); ?>" data-filter="<?php echo $server['server_description']; ?>">
|
||||||
|
<?php echo $server['server_description']; ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="/servers?view=<?php echo $server['server_uuid'] ?>" class="btn btn-info btn-sm btn-rounded"><i class="fa-solid fa-eye"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
23
pub/bin/pages/system/pageAccessControl.php
Normal file
23
pub/bin/pages/system/pageAccessControl.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
if (isset($_GET['user_group_add'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/system/pageAccessControl_user_group_add.php');
|
||||||
|
} elseif (isset($_GET['user_group_edit'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/system/pageAccessControl_user_group_edit.php');
|
||||||
|
} elseif (isset($_GET['permission_add'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/system/pageAccessControl_permission_add.php');
|
||||||
|
} elseif (isset($_GET['permission_edit'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/system/pageAccessControl_permission_edit.php');
|
||||||
|
} elseif (isset($_GET['permission_view'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/system/pageAccessControl_permission_view.php');
|
||||||
|
} elseif (isset($_GET['admin_add'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/system/pageAccessControl_admin_add.php');
|
||||||
|
} elseif (isset($_GET['admin_edit'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/system/pageAccessControl_admin_edit.php');
|
||||||
|
} elseif (isset($_GET['admin_view'])) {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/system/pageAccessControl_admin_view.php');
|
||||||
|
} else {
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/pages/system/pageAccessControl_view.php');
|
||||||
|
}
|
||||||
122
pub/bin/pages/system/pageAccessControl_admin_add.php
Normal file
122
pub/bin/pages/system/pageAccessControl_admin_add.php
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-access-admins', 'RW', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'] = true;
|
||||||
|
$jsScriptLoadData['Generatepassword'] = true;
|
||||||
|
$jsScriptLoadData['passwordGenOnLoad'] = true;
|
||||||
|
$jsScriptLoadData['passwordShowHide'] = true;
|
||||||
|
$jsScriptLoadData['passwordRegen'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$pageNavbar->AddHTMLButton('<button class="btn btn-danger mx-3" type="button" disabled><i class="fas fa-trash-alt"></i>' . __('delete') . '</button>');
|
||||||
|
$pageNavbar->AddHTMLButton('<a href="?admin_add="><button class="btn btn-primary"><i class="fas fa-plus text-success"></i>' . __('add_admin') . '</button></a>');
|
||||||
|
$formBuilder = new formBuilder('add_admin', '<i class="fas fa-plus"></i>', '/accesscontrol/#user-groups');
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$user_groups_data = $GLOBALS['conn']->query("SELECT * FROM vc_user_groups WHERE user_group_type = 'admin' ORDER BY user_group_weight DESC");
|
||||||
|
$user_groups = array();
|
||||||
|
while ($user_group = $user_groups_data->fetch_assoc()) {
|
||||||
|
array_push($user_groups, $user_group);
|
||||||
|
$last_weight = $user_group['user_group_weight'];
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('administrators'), 'href' => '/accesscontrol/#administrators'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('add_admin'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
$formBuilder->startForm();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="POST" action="/api/v1/users/">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="col">
|
||||||
|
<p><?php echo __('admin_creation_instruction') ?></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_group_uuid" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_group') ?></label>
|
||||||
|
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<select id="user_group_uuid" name="user_group_uuid" class="form-control" required>
|
||||||
|
<?php foreach ($user_groups as $user_group) {
|
||||||
|
if ($user_group['user_group_weight'] >= $_SESSION['user']['user_group_weight']) { ?>
|
||||||
|
<option value="<?php echo $user_group['user_group_uuid'] ?>"><?php echo $user_group['user_group_name'] ?></option>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
<!-- Options should be dynamically generated from the database -->
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_email" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_email') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="email" class="form-control" id="user_email" name="user_email" placeholder="user@example.xxx" required autofill="off" autofocus autocomplete="off"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_first_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('first_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_first_name" name="user_first_name" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Last Name -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_last_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('last_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_last_name" name="user_last_name" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Phone Number -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_phone_number" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('phone_number') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_phone_number" name="user_phone_number" placeholder="+1234542069"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- User Status -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_status" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_status') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<select id="user_status" name="user_status" class="form-control" required>
|
||||||
|
<option value="inactive"><?php echo __('inactive') ?></option>
|
||||||
|
<option value="banned"><?php echo __('banned') ?></option>
|
||||||
|
<option value="pending" selected><?php echo __('pending') ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php $formBuilder->formFooter(); ?>
|
||||||
|
</form>
|
||||||
|
<?php $formBuilder->endForm(); ?>
|
||||||
158
pub/bin/pages/system/pageAccessControl_admin_edit.php
Normal file
158
pub/bin/pages/system/pageAccessControl_admin_edit.php
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-access-admins', 'RW', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$pageNavbar->AddHTMLButton('<button class="btn btn-danger mx-3" type="button" disabled><i class="fas fa-trash-alt"></i>' . __('delete') . '</button>');
|
||||||
|
$pageNavbar->AddHTMLButton('<a href="?admin_add="><button class="btn btn-primary"><i class="fas fa-plus text-success"></i>' . __('add_admin') . '</button></a>');
|
||||||
|
$formBuilder = new formBuilder('edit_admin', '<i class="fas fa-plus"></i>', '/accesscontrol/#user-groups');
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$user_groups_data = $GLOBALS['conn']->query("SELECT * FROM vc_user_groups WHERE user_group_type = 'admin' ORDER BY user_group_weight DESC");
|
||||||
|
$user_groups = array();
|
||||||
|
$admin_data = false;
|
||||||
|
while ($user_group = $user_groups_data->fetch_assoc()) {
|
||||||
|
array_push($user_groups, $user_group);
|
||||||
|
$last_weight = $user_group['user_group_weight'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_uuid = $_GET['admin_edit'];
|
||||||
|
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM vc_users INNER JOIN vc_user_groups ON vc_users.user_group_uuid = vc_user_groups.user_group_uuid WHERE user_uuid = ?");
|
||||||
|
$stmt->bind_param("s", $user_uuid);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
if ($result->num_rows == 1) {
|
||||||
|
$admin_data = $result->fetch_assoc();
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('administrators'), 'href' => '/accesscontrol/#administrators'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('edit_admin'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
if ($admin_data) {
|
||||||
|
$formBuilder->startForm(); ?>
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/users/">
|
||||||
|
<input type="hidden" name="_method" value="PUT">
|
||||||
|
<input type="hidden" name="_return" value="/accesscontrol/?admin_view=<?php echo $user_uuid ?>">
|
||||||
|
<input type="hidden" name="user_uuid" value="<?php echo $user_uuid; ?>"/>
|
||||||
|
<div class="card-body">
|
||||||
|
<!-- User Group -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_group_uuid" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_group') ?></label>
|
||||||
|
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<select id="user_group_uuid" name="user_group_uuid" class="form-control" required>
|
||||||
|
<?php foreach ($user_groups as $user_group) {
|
||||||
|
if ($user_group['user_group_weight'] >= $_SESSION['user']['user_group_weight']) { ?>?>
|
||||||
|
<option <?php echo(($admin_data['user_group_uuid'] == $user_group['user_group_uuid']) ? 'selected' : '') ?> value="<?php echo $user_group['user_group_uuid'] ?>"><?php echo $user_group['user_group_name'] ?></option>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_email" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_email') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="email" class="form-control" id="user_email" name="user_email" value="<?php echo $admin_data['user_email'] ?>" placeholder="user@example.xxx" required autofill="off" autocomplete="off"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_first_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('first_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_first_name" name="user_first_name" value="<?php echo $admin_data['user_first_name'] ?>" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Last Name -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_last_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('last_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_last_name" name="user_last_name" value="<?php echo $admin_data['user_last_name'] ?>" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Phone Number -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_phone_number" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('phone_number') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_phone_number" name="user_phone_number" placeholder="+1234542069" value="<?php echo $admin_data['user_phone_number'] ?>"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- User Status -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_status" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_status') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<select id="user_status" name="user_status" class="form-control" required>
|
||||||
|
<option value="active" <?php echo(($admin_data['user_status'] == 'active') ? 'selected' : '') ?> ><?php echo __('active') ?></option>
|
||||||
|
<option value="inactive" <?php echo(($admin_data['user_status'] == 'inactive') ? 'selected' : '') ?>><?php echo __('inactive') ?></option>
|
||||||
|
<option value="banned" <?php echo(($admin_data['user_status'] == 'banned') ? 'selected' : '') ?>><?php echo __('banned') ?></option>
|
||||||
|
<option value="pending" <?php echo(($admin_data['user_status'] == 'pending') ? 'selected' : '') ?>><?php echo __('pending') ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Preferred Language -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_pref_language" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('preferred_language') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<select id="user_pref_language" name="user_pref_language" class="form-control">
|
||||||
|
<option value="none" selected>Browser language</option>
|
||||||
|
<?php foreach (scandir($_SERVER['DOCUMENT_ROOT'] . '/bin/locales/') as $file) {
|
||||||
|
if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
|
||||||
|
$language = str_replace('.php', '', $file); ?>
|
||||||
|
<option <?php echo(($admin_data['user_pref_language'] == $language) ? 'selected' : '') ?> value="<?php echo $language ?>"><?php echo __($language) ?></option>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($GLOBALS['modules_enabled']['office']) { ?>
|
||||||
|
<!-- Stompbable -->
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_stompable" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('stompable') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<select id="user_stompable" name="user_stompable" class="form-control">
|
||||||
|
<option <?php echo(($admin_data['user_stompable'] == 0) ? 'selected' : '') ?> value="0">Disabled</option>
|
||||||
|
<option <?php echo(($admin_data['user_stompable'] == 1) ? 'selected' : '') ?> value="1">Enabled</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
<?php $formBuilder->formFooter(); ?>
|
||||||
|
</form>
|
||||||
|
<?php $formBuilder->endForm(); ?><?php } else { ?>
|
||||||
|
<p>no admin with this uuid found.</p>
|
||||||
|
<?php } ?>
|
||||||
328
pub/bin/pages/system/pageAccessControl_admin_view.php
Normal file
328
pub/bin/pages/system/pageAccessControl_admin_view.php
Normal file
@@ -0,0 +1,328 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use api\classes\API_apitoken;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_apitoken.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-access-admins', 'RO', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['Generatepassword'] = true;
|
||||||
|
$jsScriptLoadData['passwordShowHide'] = true;
|
||||||
|
$jsScriptLoadData['passwordRegen'] = true;
|
||||||
|
$jsScriptLoadData['enableButtonOnImageUpload'] = true;
|
||||||
|
$jsScriptLoadData['delete_confirmation'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
$jsScriptLoadData['updateToggle'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
if ($API->checkPermissions('admin-access-admins', 'RW', true)) {
|
||||||
|
$pageNavbar->AddHTMLButton('<button class="btn btn-danger" type="button" disabled><i class="fas fa-trash-alt"></i> ' . __('delete') . '</button>');
|
||||||
|
$admin_view = htmlspecialchars($_GET['admin_view'], ENT_QUOTES, 'UTF-8');
|
||||||
|
$pageNavbar->AddHTMLButton('<a class="btn btn-primary mx-3" type="button" href="?admin_edit=' . $admin_view . '"><i class="fas fa-edit text-warning"></i> ' . __('edit') . '</a>');
|
||||||
|
$pageNavbar->AddHTMLButton('<a href="?admin_add="><button class="btn btn-primary"><i class="fas fa-plus text-success"></i> ' . __('add_admin') . '</button></a>');
|
||||||
|
}
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$user_groups_data = $GLOBALS['conn']->query("SELECT * FROM vc_user_groups WHERE user_group_type = 'admin' ORDER BY user_group_weight DESC");
|
||||||
|
$user_groups = array();
|
||||||
|
$admin_data = false;
|
||||||
|
while ($user_group = $user_groups_data->fetch_assoc()) {
|
||||||
|
array_push($user_groups, $user_group);
|
||||||
|
$last_weight = $user_group['user_group_weight'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_uuid = $_GET['admin_view'];
|
||||||
|
$stmt = $GLOBALS['conn']->prepare("SELECT * FROM vc_users INNER JOIN vc_user_groups ON vc_users.user_group_uuid = vc_user_groups.user_group_uuid WHERE user_uuid = ?");
|
||||||
|
$stmt->bind_param("s", $user_uuid);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
if ($result->num_rows == 1) {
|
||||||
|
$admin_data = $result->fetch_assoc();
|
||||||
|
}
|
||||||
|
|
||||||
|
$_GET['user_uuid'] = $user_uuid;
|
||||||
|
|
||||||
|
$API_token = new API_apitoken();
|
||||||
|
$requiredFields = ['user_uuid' => ['type' => 'uuid']];
|
||||||
|
$API_token->validateData($requiredFields);
|
||||||
|
$apitokens = $API_token->getTokens();
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('administrators'), 'href' => '/accesscontrol/#administrators'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('view'), 'href' => ''));
|
||||||
|
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
|
||||||
|
if ($admin_data) { ?>
|
||||||
|
<div class="row d-flex align-items-stretch pb-2">
|
||||||
|
<div class="col-md-4 pb-4">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<form method="POST" action="/api/v1/users/avatar/" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="user_uuid" value="<?php echo $admin_data['user_uuid'] ?>">
|
||||||
|
<h1 class="text-center"><?php echo $admin_data['user_full_name'] ?></h1>
|
||||||
|
<div class="form-group form-show-validation row align-items-center justify-content-center">
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-file input-file-image">
|
||||||
|
<img class="img-upload-preview w-100" src="<?php echo(($admin_data['user_profile_picture'] != null) ? 'data:image/png;base64, ' . $admin_data['user_profile_picture'] : '/src/images/user-avatar-default-small.png') ?>" alt="user_profile_picture">
|
||||||
|
<?php if ($API->checkPermissions('admin-access-admins', 'RW', true)) { ?>
|
||||||
|
<input type="file" class="form-control form-control-file" id="user_profile_picture" name="user_profile_picture" accept="image/png" data-enable-button="user_profile_change">
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group form-show-validation row justify-content-center">
|
||||||
|
<div class="d-flex flex-column align-items-center">
|
||||||
|
<?php if ($API->checkPermissions('admin-access-admins', 'RW', true)) { ?>
|
||||||
|
<label for="user_profile_picture" class="label-input-file btn btn-black btn-round mb-4">
|
||||||
|
<span class="btn-label"><i class="fa fa-file-image"></i></span>
|
||||||
|
<?php echo __('upload_image') ?>
|
||||||
|
</label>
|
||||||
|
<button id="user_profile_change" type="submit" class="btn btn-primary opacity-0 transition-opacity" disabled>
|
||||||
|
<i class="fa-solid fa-floppy-disk"></i> <?php echo __('save') ?>
|
||||||
|
</button>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-8 pb-4">
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-body">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>user_uuid:</td>
|
||||||
|
<td><?php echo $admin_data['user_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_group_uuid:</td>
|
||||||
|
<td><?php echo $admin_data['user_group_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_group_name:</td>
|
||||||
|
<td><?php echo $admin_data['user_group_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_group_slugify:</td>
|
||||||
|
<td><?php echo $admin_data['user_group_slugify'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_email:</td>
|
||||||
|
<td><?php echo $admin_data['user_email'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_first_name:</td>
|
||||||
|
<td><?php echo $admin_data['user_first_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_last_name:</td>
|
||||||
|
<td><?php echo $admin_data['user_last_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_full_name:</td>
|
||||||
|
<td><?php echo $admin_data['user_full_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_phone_number: </td>
|
||||||
|
<td><?php echo $admin_data['user_phone_number'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_status: </td>
|
||||||
|
<td><?php echo $admin_data['user_status'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_password_reset_expires: </td>
|
||||||
|
<td><?php echo $admin_data['user_password_reset_expires'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_two_factor_enabled: </td>
|
||||||
|
<td><?php echo $admin_data['user_two_factor_enabled'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_verified_email: </td>
|
||||||
|
<td><?php echo $admin_data['user_verified_email'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_verified_phone: </td>
|
||||||
|
<td><?php echo $admin_data['user_verified_phone'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_create_timestamp: </td>
|
||||||
|
<td><?php showTime($admin_data['user_create_timestamp']) ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_modified_timestamp: </td>
|
||||||
|
<td><?php showTime($admin_data['user_modified_timestamp']) ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_last_login_timestamp: </td>
|
||||||
|
<td><?php showTime($admin_data['user_last_login_timestamp']) ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_login_attempts: </td>
|
||||||
|
<td><?php echo $admin_data['user_login_attempts'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>user_pref_language: </td>
|
||||||
|
<td><?php echo $admin_data['user_pref_language'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php if ($GLOBALS['modules_enabled']['office']) { ?>
|
||||||
|
<tr>
|
||||||
|
<td>user_stompable: </td>
|
||||||
|
<td><?php echo $admin_data['user_stompable'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header pt-2 pb-1">
|
||||||
|
<h4>email-preferences</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
to be made
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header pt-2 pb-1">
|
||||||
|
<h4><?php echo __('user_management') ?></h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<?php if ($API->checkPermissions('admin-access-admins-mfa', 'RW', true)) { ?>
|
||||||
|
<div id="mfa-enabled-row" class="row" style="display: <?php echo(($admin_data['user_two_factor_enabled']) ? '' : 'none') ?>">
|
||||||
|
<div class="col-auto">
|
||||||
|
<a href="#" class="btn btn-danger delete-btn" data-item-uuid="<?php echo $admin_data['user_uuid'] ?>" data-api-url="/api/v1/users/mfa/" data-item-name='user_uuid' data-delete-action='{"mfa-enabled-row":"hide", "mfa-disabled-row":"show"}'>
|
||||||
|
<i class="fa-solid fa-lock"></i> <?php echo __('reset_mfa') ?>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="mfa-disabled-row" class="row" style="display: <?php echo(($admin_data['user_two_factor_enabled'] == 1) ? 'none' : '') ?>">
|
||||||
|
<div class="col-auto">
|
||||||
|
<button class="btn btn-danger delete-btn" href="#" disabled>
|
||||||
|
<i class="fa-solid fa-lock"></i> <?php echo __('reset_mfa') ?>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-access-admins-resetpassword', 'RW', true)) { ?>
|
||||||
|
<form method="post" action="/api/v1/users/resetpassword/">
|
||||||
|
<input type="hidden" name="user_uuid" value="<?php echo $user_uuid ?>">
|
||||||
|
<button class="btn btn-primary mt-2">
|
||||||
|
<i class="fa-solid fa-lock"></i> <?php echo __('send_password_reset') ?>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<?php } ?>
|
||||||
|
reset the verified email (to be made)<br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php if ($API_token->checkPermissions('user-apitoken-others', 'RO', true)) { ?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card">
|
||||||
|
|
||||||
|
<div class="card-header d-flex justify-content-between align-items-center pt-2 pb-1">
|
||||||
|
<h4 class="mb-0">API Tokens</h4>
|
||||||
|
<?php if ($API_token->checkPermissions('user-apitoken-others', 'RW', true)) { ?>
|
||||||
|
<form method="POST" action="/api/v1/users/apitoken/">
|
||||||
|
<input type="hidden" name="user_uuid" value="<?php echo $user_uuid ?>">
|
||||||
|
<input type="hidden" name="_return" value="/accesscontrol/?admin_view=<?php echo $user_uuid ?>">
|
||||||
|
<button type="submit" href="#" class="btn btn-primary">
|
||||||
|
<i class="fa-solid fa-plus"></i> Generate new token
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<table class="table table-hover table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>token</th>
|
||||||
|
<th>Expiration</th>
|
||||||
|
<th>Created</th>
|
||||||
|
<th>Last used</th>
|
||||||
|
<th>Revoked</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($apitokens as $token_data) { ?>
|
||||||
|
<tr>
|
||||||
|
<td class="text-nowrap" style="max-width: 100%;">
|
||||||
|
<div class="d-flex align-items-center gap-2" style="max-width: 100%;">
|
||||||
|
<div class="text-truncate" style="max-width: 200px;">
|
||||||
|
<?php echo substr($token_data['api_token'], 0, 15) . '...'; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td><?php showTime($token_data['api_token_expiration_timestamp']) ?></td>
|
||||||
|
<td><?php showTime($token_data['api_token_created_timestamp']) ?></td>
|
||||||
|
<td><?php showTime($token_data['api_token_last_used_timestamp']) ?></td>
|
||||||
|
<td>
|
||||||
|
<label class="switch">
|
||||||
|
<input type="checkbox" class="checkbox" data-api-data='<?php echo json_encode(['api_token_uuid' => $token_data['api_token_uuid'], 'api_token_revoked' => $token_data['api_token_revoked'] ? 1 : 0]) ?>' data-api-changevalue="api_token_revoked" data-api-url="/api/v1/users/apitoken/" <?php echo((($token_data['api_token_revoked'])) ? 'checked' : '') ?>>
|
||||||
|
<div class="slider"></div>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
<?php if ($API_token->checkPermissions('user-apitoken-others', 'RW', true)) { ?>
|
||||||
|
<td class="text-nowrap">
|
||||||
|
<a href="#" class="btn btn-danger btn-sm btn-rounded delete-btn" data-item-uuid="<?php echo $token_data['api_token_uuid'] ?>" data-item-name="api_token_uuid" data-api-url="/api/v1/users/apitoken/"><i class="fas fa-trash-alt"></i></a>
|
||||||
|
</td>
|
||||||
|
<?php } ?>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header pt-2 pb-1">
|
||||||
|
<h4>User history</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
To be made. Its going show the history of the administrator.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php } else {
|
||||||
|
echo 'admin not found';
|
||||||
|
}
|
||||||
93
pub/bin/pages/system/pageAccessControl_permission_add.php
Normal file
93
pub/bin/pages/system/pageAccessControl_permission_add.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php';
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->isSuperuser()) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'][] = true;
|
||||||
|
$jsScriptLoadData['slugify'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$formBuilder = new formBuilder('add_permission', '<i class="fas fa-plus"></i>', '/accesscontrol/#permissions');
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$system_modules_data = $GLOBALS['conn']->query("SELECT * FROM system_modules WHERE module_enabled = 1");
|
||||||
|
$system_modules = array();
|
||||||
|
while ($module = $system_modules_data->fetch_assoc()) {
|
||||||
|
array_push($system_modules, $module);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('permission'), 'href' => '/accesscontrol/#permissions'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('add_permission'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
$formBuilder->startForm();
|
||||||
|
?>
|
||||||
|
<form id="FormValidation" method="POST" action="/api/v1/permissions/">
|
||||||
|
<input type="hidden" name="_return" value="/accesscontrol/#permission">
|
||||||
|
<div class="card-body">
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="permission_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('permission_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="permission_name" name="permission_name" placeholder="" data-slugify="permission_slugify" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="permission_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('permission_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="permission_slugify" name="permission_slugify" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="module_uuid" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('module') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="module_uuid" name="module_uuid" class="form-control" required>
|
||||||
|
<option value=""></option>
|
||||||
|
<?php
|
||||||
|
foreach ($system_modules as $module) { ?>
|
||||||
|
<option value="<?php echo $module['module_uuid'] ?>"> <?php echo $module['module_name'] ?></option>
|
||||||
|
<?php } ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="permission_description" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('permission_description') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<textarea type="text" class="form-control" id="permission_description" name="permission_description" placeholder="" required rows="5"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php $formBuilder->formFooter(); ?>
|
||||||
|
</form>
|
||||||
|
<?php $formBuilder->endForm(); ?>
|
||||||
106
pub/bin/pages/system/pageAccessControl_permission_edit.php
Normal file
106
pub/bin/pages/system/pageAccessControl_permission_edit.php
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use api\classes\API_permissions;
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php';
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_permissions.php';
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-access-control-permissions', 'RW', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'][] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$formBuilder = new formBuilder('edit_permission', '<i class="fas fa-plus"></i>', '/accesscontrol/#permission');
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$permission_uuid = $_GET['permission_edit'];
|
||||||
|
$_GET['permission_uuid'] = $permission_uuid;
|
||||||
|
$API_permissions = new API_permissions();
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'permission_uuid', 1 => $permission_uuid]]];
|
||||||
|
$requiredFields = ['permission_uuid' => ['type' => 'uuid']];
|
||||||
|
$API_permissions->validateData($requiredFields);
|
||||||
|
$permission_data = $API_permissions->getPermission()[0];
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$system_modules_data = $GLOBALS['conn']->query("SELECT * FROM system_modules WHERE module_enabled = 1");
|
||||||
|
$system_modules = array();
|
||||||
|
while ($module = $system_modules_data->fetch_assoc()) {
|
||||||
|
array_push($system_modules, $module);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('permission'), 'href' => '/accesscontrol/#permissions'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('edit_permission'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
|
||||||
|
if ($permission_data) {
|
||||||
|
$formBuilder->startForm(); ?>
|
||||||
|
<form id="FormValidation" method="post" action="/api/v1/permissions/">
|
||||||
|
<input type="hidden" name="_return" value="/accesscontrol/?permission_view=<?php echo $permission_uuid ?>">
|
||||||
|
<input type="hidden" name="_method" value="PUT">
|
||||||
|
<input type="hidden" name="permission_uuid" value="<?php echo $permission_uuid ?>">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="permission_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('permission_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="permission_name" name="permission_name" value="<?php echo $permission_data['permission_name'] ?>" placeholder="" data-slugify="permission_slugify" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="permission_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('permission_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="permission_slugify" name="permission_slugify" value="<?php echo $permission_data['permission_slugify'] ?>" placeholder="" disabled/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="module_uuid" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('module') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="module_uuid" name="module_uuid" class="form-control" required>
|
||||||
|
<option value=""></option>
|
||||||
|
<?php
|
||||||
|
foreach ($system_modules as $module) { ?>
|
||||||
|
<option value="<?php echo $module['module_uuid'] ?>" <?php echo ($module['module_uuid'] == $permission_data['module_uuid']) ? 'selected' : '' ?>> <?php echo $module['module_name'] ?></option>
|
||||||
|
<?php } ?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="permission_description" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('permission_description') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<textarea type="text" class="form-control" id="permission_description" name="permission_description" placeholder="" required rows="5"><?php echo $permission_data['permission_description'] ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php $formBuilder->formFooter(); ?>
|
||||||
|
</form>
|
||||||
|
<?php $formBuilder->endForm(); ?><?php } else {
|
||||||
|
echo 'permission not found';
|
||||||
|
} ?>
|
||||||
153
pub/bin/pages/system/pageAccessControl_permission_view.php
Normal file
153
pub/bin/pages/system/pageAccessControl_permission_view.php
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use api\classes\API_permissions;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php';
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_permissions.php';
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-access-control-permissions', 'RO', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['delete_confirmation'] = true;
|
||||||
|
$jsScriptLoadData['datatables'] = true;
|
||||||
|
$jsScriptLoadData['updatePermissions'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
if ($API->isSuperuser()) {
|
||||||
|
$pageNavbar->AddHTMLButton('<button class="btn btn-danger" type="button" disabled><i class="fas fa-trash-alt"></i> ' . __('delete') . '</button>');
|
||||||
|
}
|
||||||
|
if ($API->checkPermissions('admin-access-control-permissions', 'RW', true)) {
|
||||||
|
$permission_view = htmlspecialchars($_GET['permission_view'], ENT_QUOTES, 'UTF-8');
|
||||||
|
$pageNavbar->AddHTMLButton('<a class="btn btn-primary mx-3" type="button" href="?permission_edit=' . $permission_view . '"><i class="fas fa-edit text-warning"></i> ' . __('edit') . '</a>');
|
||||||
|
}
|
||||||
|
if ($API->isSuperuser()) {
|
||||||
|
$pageNavbar->AddHTMLButton('<a href="?permission_add="><button class="btn btn-primary"><i class="fas fa-plus text-success"></i> ' . __('add_permission') . '</button></a>');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$permission_uuid = $_GET['permission_view'];
|
||||||
|
$_GET['permission_uuid'] = $permission_uuid;
|
||||||
|
$API_permissions = new API_permissions();
|
||||||
|
$requiredFields = ['permission_uuid' => ['type' => 'uuid']];
|
||||||
|
$API_permissions->validateData($requiredFields);
|
||||||
|
$permission_data = $API_permissions->getPermissionRights();
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('permission'), 'href' => '/accesscontrol/#permissions'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('view'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
|
||||||
|
if ($permission_data) { ?>
|
||||||
|
<h2>
|
||||||
|
<i class="fa-solid fa-lock"></i> <?php echo $permission_data[0]['permission_name'] ?>
|
||||||
|
</h2>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>permission_uuid:</td>
|
||||||
|
<td><?php echo $permission_data[0]['permission_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>permission_name:</td>
|
||||||
|
<td><?php echo $permission_data[0]['permission_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>permission_slugify:</td>
|
||||||
|
<td><?php echo $permission_data[0]['permission_slugify'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>permission_description:</td>
|
||||||
|
<td><?php echo $permission_data[0]['permission_description'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>module_uuid:</td>
|
||||||
|
<td><?php echo $permission_data[0]['module_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>permission_create_timestamp:</td>
|
||||||
|
<td><?php showTime($permission_data[0]['permission_create_timestamp']); ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>permission_modified_datetime:</td>
|
||||||
|
<td><?php showTime($permission_data[0]['permission_modified_timestamp']); ?></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="multi-filter-select display table table-striped table-hover" data-skip-columns="0,5">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('user_group') ?></th>
|
||||||
|
<th><?php echo __('NA') ?></th>
|
||||||
|
<th><?php echo __('RO') ?></th>
|
||||||
|
<th><?php echo __('RW') ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('user_group') ?></th>
|
||||||
|
<th><?php echo __('NA') ?></th>
|
||||||
|
<th><?php echo __('RO') ?></th>
|
||||||
|
<th><?php echo __('RW') ?></th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
foreach ($permission_data as $permission_data_group) {
|
||||||
|
if ($permission_data_group['user_group_slugify'] != 'superuser') { ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo $permission_data_group['user_group_slugify'] ?> </td>
|
||||||
|
<td>
|
||||||
|
<label class="switch">
|
||||||
|
<input type="checkbox" class="checkbox" data-permission-uuid="<?= $permission_data_group['permission_uuid'] ?>" data-user-group-uuid="<?= $permission_data_group['user_group_uuid'] ?>" data-value="NA" data-api-url="/api/v1/access-rights/" <?php echo(($permission_data_group['permission_value'] == 'NA') ? 'checked' : '') ?>
|
||||||
|
<?php echo ($API->checkPermissions('admin-access-control-permissions', 'RW', true)) ? '' : 'disabled' ?>>
|
||||||
|
<div class="slider"></div>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<label class="switch">
|
||||||
|
<input type="checkbox" class="checkbox" data-permission-uuid="<?= $permission_data_group['permission_uuid'] ?>" data-user-group-uuid="<?= $permission_data_group['user_group_uuid'] ?>" data-value="RO" data-api-url="/api/v1/access-rights/" <?php echo(($permission_data_group['permission_value'] == 'RO') ? 'checked' : '') ?>
|
||||||
|
<?php echo ($API->checkPermissions('admin-access-control-permissions', 'RW', true)) ? '' : 'disabled' ?>>
|
||||||
|
<div class="slider"></div>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<label class="switch">
|
||||||
|
<input type="checkbox" class="checkbox" data-permission-uuid="<?= $permission_data_group['permission_uuid'] ?>" data-user-group-uuid="<?= $permission_data_group['user_group_uuid'] ?>" data-value="RW" data-api-url="/api/v1/access-rights/" <?php echo(($permission_data_group['permission_value'] == 'RW') ? 'checked' : '') ?>
|
||||||
|
<?php echo ($API->checkPermissions('admin-access-control-permissions', 'RW', true)) ? '' : 'disabled' ?>>
|
||||||
|
<div class="slider"></div>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?><?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } else {
|
||||||
|
echo '404 not found';
|
||||||
|
}
|
||||||
90
pub/bin/pages/system/pageAccessControl_user_group_add.php
Normal file
90
pub/bin/pages/system/pageAccessControl_user_group_add.php
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php';
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-access-control-user-groups', 'RW', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'][] = true;
|
||||||
|
$jsScriptLoadData['slugify'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$formBuilder = new formBuilder('add_user_groups', '<i class="fas fa-plus"></i>', '/accesscontrol/#user-groups');
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$user_groups_data = $GLOBALS['conn']->query("SELECT * FROM vc_user_groups ORDER BY user_group_weight ASC");
|
||||||
|
$user_groups = array();
|
||||||
|
while ($user_group = $user_groups_data->fetch_assoc()) {
|
||||||
|
array_push($user_groups, $user_group);
|
||||||
|
$last_weight = $user_group['user_group_weight'];
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('user_groups'), 'href' => '/accesscontrol/#user-groups'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('add_user_groups'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
$formBuilder->startForm();
|
||||||
|
?>
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/user-groups/">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_group_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_group_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_group_name" name="user_group_name" placeholder="" data-slugify="user_group_slugify" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_group_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_group_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_group_slugify" name="user_group_slugify" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_group_type" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_group_type') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="user_group_type" name="user_group_type" class="form-control" required>
|
||||||
|
<option value="user" selected><?php echo __('users') ?></option>
|
||||||
|
<option value="admin"><?php echo __('administrators') ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_group_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('weight') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="mb-3">
|
||||||
|
<input type="number" class="form-control" name="user_group_weight" min="1" max="900" step="1" value="<?php echo $last_weight + 10 ?>">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php $formBuilder->formFooter(); ?>
|
||||||
|
</form>
|
||||||
|
<?php $formBuilder->endForm(); ?>
|
||||||
97
pub/bin/pages/system/pageAccessControl_user_group_edit.php
Normal file
97
pub/bin/pages/system/pageAccessControl_user_group_edit.php
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use api\classes\API_usergroups;
|
||||||
|
use bin\php\Classes\formBuilder;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/formBuilder.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_usergroups.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
if (!$API->checkPermissions('admin-access-control-user-groups', 'RW', true)) {
|
||||||
|
echo 'error 401 unauthorized';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['form'] = true;
|
||||||
|
$jsScriptLoadData['slugify'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
$formBuilder = new formBuilder('edit_user_groups', '<i class="fas fa-plus"></i>', '/accesscontrol/#user-groups');
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$user_group_uuid = $_GET['user_group_edit'];
|
||||||
|
$_GET['user_group_uuid'] = $user_group_uuid;
|
||||||
|
$API_usergroups = new API_usergroups();
|
||||||
|
$_GET['builder'] = [1 => ['where' => [0 => 'user_group_uuid', 1 => $user_group_uuid]]];
|
||||||
|
$requiredFields = ['user_group_uuid' => ['type' => 'uuid']];
|
||||||
|
$API_usergroups->validateData($requiredFields);
|
||||||
|
$user_group = $API_usergroups->getUsergroup()[0];
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('user_groups'), 'href' => '/accesscontrol/#user-groups'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => $user_group['user_group_name'], 'href' => '/accesscontrol/#user-groups'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('edit'), 'href' => ''));
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
$formBuilder->startForm();
|
||||||
|
?>
|
||||||
|
<form id="FormValidation" enctype="multipart/form-data" method="post" action="/api/v1/user-groups/">
|
||||||
|
<input type="hidden" name="_method" value="PUT">
|
||||||
|
<input type="hidden" name="user_group_uuid" value="<?php echo $user_group['user_group_uuid'] ?>"/>
|
||||||
|
<input type="hidden" name="user_group_slugify" value="<?php echo $user_group['user_group_slugify'] ?>"/>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_group_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_group_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_group_name" name="user_group_name" value="<?php echo $user_group['user_group_name'] ?>" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_group_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_group_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="user_group_slugify" name="user_group_slugify" value="<?php echo $user_group['user_group_slugify'] ?>" placeholder="" required disabled/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_group_type" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('user_group_type') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="select2-input">
|
||||||
|
<select id="user_group_type" name="user_group_type" class="form-control" disabled>
|
||||||
|
<option value="user" selected><?php echo __('users') ?></option>
|
||||||
|
<option value="admin"><?php echo __('administrators') ?></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="user_group_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('weight') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="mb-3">
|
||||||
|
<input type="number" class="form-control" name="user_group_weight" min="1" max="900" step="1" value="<?php echo $user_group['user_group_weight'] ?>">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php $formBuilder->formFooter(); ?>
|
||||||
|
</form>
|
||||||
|
<?php $formBuilder->endForm(); ?>
|
||||||
328
pub/bin/pages/system/pageAccessControl_view.php
Normal file
328
pub/bin/pages/system/pageAccessControl_view.php
Normal file
@@ -0,0 +1,328 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API_permissions.php');
|
||||||
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php';
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['activeTabOnRefresh'] = true;;
|
||||||
|
$jsScriptLoadData['multiFilterSelect'] = true;
|
||||||
|
$jsScriptLoadData['delete_confirmation'] = true;
|
||||||
|
$jsScriptLoadData['datatables'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$user_groups_data = $GLOBALS['conn']->query("SELECT * FROM vc_user_groups ORDER BY user_group_weight ASC");
|
||||||
|
$user_groups = array();
|
||||||
|
while ($user_group = $user_groups_data->fetch_assoc()) {
|
||||||
|
array_push($user_groups, $user_group);
|
||||||
|
$last_weight = $user_group['user_group_weight'];
|
||||||
|
}
|
||||||
|
|
||||||
|
# get all the admins
|
||||||
|
$stmt = $GLOBALS['conn']->query("SELECT * FROM vc_users INNER JOIN vc_user_groups ON vc_users.user_group_uuid = vc_user_groups.user_group_uuid WHERE user_group_type = 'admin'");
|
||||||
|
$administrators = array();
|
||||||
|
while ($row = $stmt->fetch_assoc()) {
|
||||||
|
array_push($administrators, $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$stmt = $GLOBALS['conn']->query("SELECT * FROM vc_permissions INNER JOIN system_modules ON vc_permissions.module_uuid = system_modules.module_uuid WHERE system_modules.module_enabled = 1");
|
||||||
|
$permissions = array();
|
||||||
|
while ($row = $stmt->fetch_assoc()) {
|
||||||
|
array_push($permissions, $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
?>
|
||||||
|
<div class="card-body activeTabOnRefresh" style="opacity: 0; transition: opacity 10ms;">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-1">
|
||||||
|
<div class="nav flex-column nav-pills nav-secondary nav-pills-no-bd nav-pills-icons" id="v-pills-tab-with-icon" role="tablist" aria-orientation="vertical">
|
||||||
|
<?php if ($API->checkPermissions('admin-access-admins', 'RO', true)) { ?>
|
||||||
|
<a class="nav-link active" id="administrators-tab" data-bs-toggle="pill" href="#administrators" role="tab" aria-controls="administrators" aria-selected="true">
|
||||||
|
<i class="fa-solid fa-user-tie"></i><?php echo __('administrators'); ?>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-access-control-permissions', 'RO', true)) { ?>
|
||||||
|
<a class="nav-link" id="permissions-tab" data-bs-toggle="pill" href="#permissions" role="tab" aria-controls="permissions">
|
||||||
|
<i class="fa-solid fa-lock"></i><?php echo __('permission'); ?>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-access-control-user-groups', 'RO', true)) { ?>
|
||||||
|
<a class="nav-link" id="user-groups-tab" data-bs-toggle="pill" href="#user-groups" role="tab" aria-controls="user-groups">
|
||||||
|
<i class="fa-solid fa-user-group"></i><?php echo __('user_groups'); ?>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="col-md-11">
|
||||||
|
<div class="tab-content" id="v-pills-with-icon-tabContent">
|
||||||
|
<?php if ($API->checkPermissions('admin-access-admins', 'RO', true)) { ?>
|
||||||
|
<div class="tab-pane fade show active" id="administrators" role="tabpanel" aria-labelledby="administrators-tab">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-5">
|
||||||
|
<h2>
|
||||||
|
<i class="fa-solid fa-user-tie"></i> <?php echo __('administrators') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div class="col d-flex justify-content-end">
|
||||||
|
<?php if ($API->checkPermissions('admin-access-admins', 'RW', true)) { ?>
|
||||||
|
<a href="?admin_add=">
|
||||||
|
<button class="btn btn-primary">
|
||||||
|
<i class="fas fa-plus text-success"></i> <?php echo __('add_admin') ?>
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="multi-filter-select display table table-striped table-hover" data-skip-columns="0">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('avatar') ?></th>
|
||||||
|
<th><?php echo __('full_name') ?></th>
|
||||||
|
<th><?php echo __('user_email') ?></th>
|
||||||
|
<th><?php echo __('user_state') ?></th>
|
||||||
|
<th><?php echo __('last_login') ?></th>
|
||||||
|
<th><?php echo __('user_group_name') ?></th>
|
||||||
|
<th><?php echo __('actions') ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('avatar') ?></th>
|
||||||
|
<th><?php echo __('full_name') ?></th>
|
||||||
|
<th><?php echo __('user_email') ?></th>
|
||||||
|
<th><?php echo __('user_state') ?></th>
|
||||||
|
<th><?php echo __('last_login') ?></th>
|
||||||
|
<th><?php echo __('user_group_name') ?></th>
|
||||||
|
<th><?php echo __('actions') ?></th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($administrators as $administrator) {
|
||||||
|
if ($administrator['user_email'] != 'superuser') { ?>
|
||||||
|
<tr data-item-id="<?php echo $administrator['user_uuid']; ?>">
|
||||||
|
<td class="text-nowrap">
|
||||||
|
<div class="avatar-sm ">
|
||||||
|
<img class="avatar-img rounded-circle" src="data:image/png;base64,<?php echo str_replace("'", '', $administrator['user_profile_picture']) ?>" height="50px" alt="">
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="text-nowrap"><?php echo $administrator['user_full_name'] ?></td>
|
||||||
|
<td class="text-nowrap"><?php echo $administrator['user_email'] ?></td>
|
||||||
|
<td class="text-nowrap"><?php echo $administrator['user_status'] ?></td>
|
||||||
|
<td class="text-nowrap"><?php showTime($administrator['user_last_login_timestamp']); ?></td>
|
||||||
|
<td class="text-nowrap"><?php echo $administrator['user_group_name'] ?></td>
|
||||||
|
<td class="text-nowrap">
|
||||||
|
<?php if ($API->checkPermissions('admin-access-admins', 'RW', true)) { ?>
|
||||||
|
<a href="?admin_edit=<?php echo $administrator['user_uuid'] ?>" class="btn btn-primary btn-sm btn-rounded"><i class="fas fa-edit"></i></a>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-access-admins', 'RO', true)) { ?>
|
||||||
|
<a href="?admin_view=<?php echo $administrator['user_uuid'] ?>" class="btn btn-info btn-sm btn-rounded"><i class="far fa-eye"></i></a>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-access-admins', 'RW', true)) { ?>
|
||||||
|
<a href="#" class="btn btn-danger btn-sm btn-rounded delete-btn" data-item-uuid="<?php echo $administrator['user_uuid'] ?>" data-api-url="/api/v1/users/" data-item-name="user_uuid"><i class="fas fa-trash-alt"></i></a>
|
||||||
|
<?php } ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php }
|
||||||
|
} ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-access-control-permissions', 'RO', true)) { ?>
|
||||||
|
<div class="tab-pane fade show active" id="permissions" role="tabpanel" aria-labelledby="permissions-tab">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-6">
|
||||||
|
<h2>
|
||||||
|
<i class="fa-solid fa-lock"></i> <?php echo __('permission') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div class="col d-flex justify-content-end">
|
||||||
|
<?php if ($API->isSuperuser()) { ?>
|
||||||
|
<a href="?permission_add=">
|
||||||
|
<button class="btn btn-primary">
|
||||||
|
<i class="fas fa-plus text-success"></i> <?php echo __('add_permission') ?>
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="multi-filter-select display table table-striped table-hover" data-skip-columns="2,3">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('name') ?></th>
|
||||||
|
<th><?php echo __('module') ?></th>
|
||||||
|
<th><?php echo __('description') ?></th>
|
||||||
|
<th><?php echo __('actions') ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('name') ?></th>
|
||||||
|
<th><?php echo __('module') ?></th>
|
||||||
|
<th><?php echo __('description') ?></th>
|
||||||
|
<th><?php echo __('actions') ?></th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($permissions as $key => $permission) { ?>
|
||||||
|
<tr data-item-id="<?php echo $permission['permission_uuid']; ?>">
|
||||||
|
<td class="text-nowrap"><?php echo $permission['permission_name'] ?></td>
|
||||||
|
<td class="text-nowrap"><?php echo __($permission['module_slugify']) ?></td>
|
||||||
|
<td class=""><?php echo $permission['permission_description'] ?></td>
|
||||||
|
<td class="text-nowrap">
|
||||||
|
|
||||||
|
<?php if ($API->checkPermissions('admin-access-control-permissions', 'RW', true)) { ?>
|
||||||
|
<a href="?permission_edit=<?php echo $permission['permission_uuid'] ?>" class="btn btn-primary btn-sm btn-rounded"><i class="fas fa-edit"></i></a>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<a href="?permission_view=<?php echo $permission['permission_uuid'] ?>" class="btn btn-info btn-sm btn-rounded"><i class="far fa-eye"></i></a>
|
||||||
|
<?php if ($API->isSuperuser()) { ?>
|
||||||
|
<a href="#" class="btn btn-danger btn-sm btn-rounded delete-btn" data-item-uuid="<?php echo $permission['permission_uuid'] ?>" data-item-name="permission_uuid" data-api-url="/api/v1/permissions/"><i class="fas fa-trash-alt"></i></a>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-access-control-user-groups', 'RO', true)) { ?>
|
||||||
|
<div class="tab-pane fade" id="user-groups" role="tabpanel" aria-labelledby="user-groups-tab">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-6">
|
||||||
|
<h2>
|
||||||
|
<i class="fa-solid fa-user-group"></i> <?php echo __('user_groups') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<?php if ($API->checkPermissions('admin-access-control-user-groups', 'RW', true)) { ?>
|
||||||
|
<div class="col d-flex justify-content-end">
|
||||||
|
<a href="?user_group_add=">
|
||||||
|
<button class="btn btn-primary">
|
||||||
|
<i class="fas fa-plus text-success"></i> <?php echo __('add_user_groups') ?>
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<?php
|
||||||
|
if (count($user_groups) == 0) {
|
||||||
|
echo __('no_user_groups_found');
|
||||||
|
} else { ?>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('user_group_name') ?></th>
|
||||||
|
<th><?php echo __('user_group_slugify') ?></th>
|
||||||
|
<th><?php echo __('user_group_type') ?></th>
|
||||||
|
<th class="text-nowrap text-end"><?php echo __('actions') ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<?php foreach ($user_groups as $user_group) { ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo $user_group['user_group_name']; ?></td>
|
||||||
|
<td><?php echo $user_group['user_group_slugify']; ?></td>
|
||||||
|
<td><?php echo __($user_group['user_group_type']); ?></td>
|
||||||
|
<td class="text-nowrap text-end">
|
||||||
|
<?php if ($API->checkPermissions('admin-access-control-user-groups', 'RW', true)) { ?>
|
||||||
|
<a href="?user_group_edit=<?php echo $user_group['user_group_uuid'] ?>" class="btn btn-primary btn-sm btn-rounded"><i class="fas fa-edit"></i></a>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-access-control-user-groups', 'RO', true)) { ?>
|
||||||
|
<a href="#" class="btn btn-info btn-sm btn-rounded" data-bs-toggle="modal" data-bs-target="#infoModal<?php echo $user_group['user_group_slugify'] ?>"><i class="far fa-eye"></i></a>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-access-control-user-groups', 'RW', true)) { ?>
|
||||||
|
<a href="#" class="btn btn-danger btn-sm btn-rounded delete-btn" data-item-uuid="<?php echo $user_group['user_group_uuid'] ?>" data-api-url="/api/v1/user-groups/" data-item-name="user_group_uuid"><i class="fas fa-trash-alt"></i></a>
|
||||||
|
<?php } ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</table>
|
||||||
|
<?php foreach ($user_groups as $user_group) {
|
||||||
|
if ($API->checkPermissions('admin-access-control-user-groups', 'RO', true)) { ?>
|
||||||
|
<div class="modal fade" id="infoModal<?php echo $user_group['user_group_slugify'] ?>" tabindex="-1" aria-labelledby="infoModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered modal-lg">
|
||||||
|
<div class="modal-content bg-black2">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="infoModalLabel">
|
||||||
|
<i class="fas fa-info-circle"></i> <?php echo __('information') ?>
|
||||||
|
</h5>
|
||||||
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<br>
|
||||||
|
<table class="table table-sm table-striped-bg-black">
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('uuid') ?>:</td>
|
||||||
|
<td><?php echo $user_group['user_group_uuid'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('user_group_name') ?>:</td>
|
||||||
|
<td><?php echo $user_group['user_group_name'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('user_group_slugify') ?>:</td>
|
||||||
|
<td><?php echo $user_group['user_group_slugify'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('weight') ?>:</td>
|
||||||
|
<td><?php echo $user_group['user_group_weight'] ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('create_date') ?>:</td>
|
||||||
|
<td><?php showTime($user_group['user_group_create_timestamp']) ?></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo __('last_modified_date') ?>:</td>
|
||||||
|
<td><?php showTime($user_group['user_group_modified_timestamp']); ?></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
|
} ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
55
pub/bin/pages/system/pageMonitoring.php
Normal file
55
pub/bin/pages/system/pageMonitoring.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$jsScriptLoadData['activeTabOnRefresh'] = true;
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="card-body activeTabOnRefresh" style="opacity: 0; transition: opacity 10ms;">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-1">
|
||||||
|
<div class="nav flex-column nav-pills nav-secondary nav-pills-no-bd nav-pills-icons" id="v-pills-tab-with-icon" role="tablist" aria-orientation="vertical">
|
||||||
|
|
||||||
|
<a class="nav-link active" id="overview-tab" data-bs-toggle="pill" href="#overview" role="tab" aria-controls="overview" aria-selected="true">
|
||||||
|
<i class="fa-solid fa-ear-listen"></i></i><?php echo __('overview'); ?>
|
||||||
|
</a>
|
||||||
|
<a class="nav-link" id="monitoring-tab" data-bs-toggle="pill" href="#monitoring" role="tab" aria-controls="monitoring">
|
||||||
|
<i class="fa-solid fa-magnifying-glass"></i><?php echo __('monitoring'); ?>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-11">
|
||||||
|
<div class="tab-content" id="v-pills-with-icon-tabContent">
|
||||||
|
<div class="tab-pane fade show active" id="overview" role="tabpanel" aria-labelledby="overview-tab">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-4">
|
||||||
|
<h2>
|
||||||
|
<i class="fa-solid fa-ear-listen"></i></i> <?php echo __('overview') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
to be made
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane fade" id="monitoring" role="tabpanel" aria-labelledby="monitoring-tab">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-4">
|
||||||
|
<h2>
|
||||||
|
<i class="fa-solid fa-magnifying-glass"></i> <?php echo __('monitoring') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
to be made
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
343
pub/bin/pages/system/pageSystemConfig.php
Normal file
343
pub/bin/pages/system/pageSystemConfig.php
Normal file
@@ -0,0 +1,343 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['activeTabOnRefresh'] = true;
|
||||||
|
$jsScriptLoadData['copyInputValue'] = true;
|
||||||
|
$jsScriptLoadData['updateToggle'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$portal_settings = $GLOBALS['conn']->query("SELECT * FROM vc_portal_settings")->fetch_assoc();
|
||||||
|
|
||||||
|
$system_modules_data = $GLOBALS['conn']->query("SELECT * FROM system_modules");
|
||||||
|
$system_modules = array();
|
||||||
|
while ($module = $system_modules_data->fetch_assoc()) {
|
||||||
|
array_push($system_modules, $module);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
|
||||||
|
?>
|
||||||
|
<div class="card-body activeTabOnRefresh" style="opacity: 0; transition: opacity 10ms;">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-1 col-lg-1">
|
||||||
|
<div class="nav flex-column nav-pills nav-secondary nav-pills-no-bd nav-pills-icons" id="v-pills-tab-with-icon" role="tablist" aria-orientation="vertical">
|
||||||
|
<?php if ($API->checkPermissions('admin-portalsettings', 'RO', true)) { ?>
|
||||||
|
<a class="nav-link" id="global-settings-tab" data-bs-toggle="pill" href="#global-settings" role="tab" aria-controls="global-settings" aria-selected="true">
|
||||||
|
<i class="fas fa-globe-americas"></i><?php echo __('global_settings'); ?>
|
||||||
|
</a>
|
||||||
|
<?php
|
||||||
|
} ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-mailsettings', 'RO', true)) {
|
||||||
|
|
||||||
|
?>
|
||||||
|
<a class="nav-link" id="mail-settings-tab" data-bs-toggle="pill" href="#mail-settings" role="tab" aria-controls="mail-settings">
|
||||||
|
<i class="fa-solid fa-envelope"></i><?php echo __('mail_settings'); ?>
|
||||||
|
</a>
|
||||||
|
<?php
|
||||||
|
} ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-modules', 'RO', true)) {
|
||||||
|
$first_nav_active = true; ?>
|
||||||
|
<a class="nav-link" id="mail-settings-tab" data-bs-toggle="pill" href="#modules" role="tab" aria-controls=modules">
|
||||||
|
<i class="fa-solid fa-cubes"></i><?php echo __('modules'); ?>
|
||||||
|
</a>
|
||||||
|
<?php $first_nav_active = true;
|
||||||
|
} ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-sources', 'RO', true)) {
|
||||||
|
$first_nav_active = true; ?>
|
||||||
|
<a class="nav-link" id="sources-tab" data-bs-toggle="pill" href="#sources" role="tab" aria-controls=sources">
|
||||||
|
<i class="fa-solid fa-cloud"></i><?php echo __('sources'); ?>
|
||||||
|
</a>
|
||||||
|
<?php $first_nav_active = true;
|
||||||
|
} ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-11 col-lg-11">
|
||||||
|
<div class="tab-content" id="v-pills-with-icon-tabContent">
|
||||||
|
<?php if ($API->checkPermissions('admin-portalsettings', 'RO', true)) { ?>
|
||||||
|
<div class="tab-pane fade show active" id="global-settings" role="tabpanel" aria-labelledby="global-settings-tab">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-12">
|
||||||
|
<h2>
|
||||||
|
<i class="fas fa-globe-americas"></i> <?php echo __('global_settings') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<form id="FormValidation" method="post" action="/api/v1/portalsettings/">
|
||||||
|
<input type="hidden" name="_method" value="PUT">
|
||||||
|
<input type="hidden" name="_return" value="/systemconfig/#global-settings">
|
||||||
|
<input type="hidden" name="portal_uuid" value="<?php echo $portal_settings['portal_uuid']; ?>">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="portal_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('portal_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="portal_name" name="portal_name" value="<?php echo $portal_settings['portal_name'] ?>" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="portal_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('portal_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="portal_slugify" name="portal_slugify" value="<?php echo $portal_settings['portal_slugify'] ?>" placeholder="" required disabled/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="portal_provider_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('portal_provider_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="portal_provider_name" name="portal_provider_name" value="<?php echo $portal_settings['portal_provider_name'] ?>" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="portal_provider_slugify" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('portal_provider_slugify') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="portal_provider_slugify" name="portal_provider_slugify" value="<?php echo $portal_settings['portal_provider_slugify'] ?>" placeholder="" disabled/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="admin_auth_methods" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('admin_auth_methods') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="admin_auth_methods" name="admin_auth_methods" value="<?php echo $portal_settings['admin_auth_methods'] ?>" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="cacert_url" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2">
|
||||||
|
<?php echo __('cacert_url') ?>
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" class="form-control" id="cacert_url" name="cacert_url" value="<?php echo $portal_settings['cacert_url'] ?>" placeholder="" disabled/>
|
||||||
|
<button class="btn btn-outline-secondary" type="button" onclick="copyToClipboard('cacert_url')">
|
||||||
|
<i class="fas fa-copy"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="autop_url" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2">
|
||||||
|
<?php echo __('autop_url') ?>
|
||||||
|
</label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" class="form-control" id="autop_url" name="autop_url" value="<?php echo $portal_settings['autop_url'] ?>" placeholder="" disabled/>
|
||||||
|
<button class="btn btn-outline-secondary" type="button" onclick="copyToClipboard('autop_url')">
|
||||||
|
<i class="fas fa-copy"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer py-4">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col d-flex justify-content-end">
|
||||||
|
<?php if ($API->checkPermissions('admin-portalsettings', 'RW', true)) { ?>
|
||||||
|
<button type="submit" class="btn btn-primary">
|
||||||
|
<i class="fas fa-edit"></i> <?php echo __('edit') ?>
|
||||||
|
</button>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-mailsettings', 'RO', true)) { ?>
|
||||||
|
<div class="tab-pane fade show active" id="mail-settings" role="tabpanel" aria-labelledby="mail-settings-tab">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-12">
|
||||||
|
<h2>
|
||||||
|
<i class="fa-solid fa-envelope"></i> <?php echo __('mail_settings') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card">
|
||||||
|
<form id="FormValidation" method="post" action="/api/v1/mailsettings/">
|
||||||
|
<input type="hidden" name="portal_uuid" value="<?php echo $portal_settings['portal_uuid']; ?>">
|
||||||
|
<input type="hidden" name="_method" value="PUT">
|
||||||
|
<input type="hidden" name="_return" value="/systemconfig/#mail-settings">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="mail_from_name" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('mail_from_name') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="mail_from_name" name="mail_from_name" value="<?php echo $portal_settings['mail_from_name'] ?>" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="mail_from_address" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('mail_from_address') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="email" class="form-control" name="mail_from_address" value="<?php echo $portal_settings['mail_from_address'] ?>" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="mail_smtp_host" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('mail_smtp_host') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" name="mail_smtp_host" value="<?php echo $portal_settings['mail_smtp_host'] ?>" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="mail_smtp_secure" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('mail_smtp_secure') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<select id="mail_smtp_secure" name="mail_smtp_secure" class="form-control" required>
|
||||||
|
<option value="tls" <?php echo ($portal_settings['mail_smtp_secure'] == 'tls') ? 'selected' : '' ?>>TLS (standard port 587)</option>
|
||||||
|
<option value="ssl" <?php echo ($portal_settings['mail_smtp_secure'] == 'ssl') ? 'selected' : '' ?>>SSL (standard port 465)</option>
|
||||||
|
<option value="no" <?php echo ($portal_settings['mail_smtp_secure'] == 'no') ? 'selected' : '' ?>>No Encryption (standard port 25)</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="mail_smtp_port" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('mail_smtp_port') ?></label>
|
||||||
|
<div class="col-lg-2 col-md-2 col-sm-2">
|
||||||
|
<input type="number" class="form-control" id="mail_smtp_port" name="mail_smtp_port" value="<?php echo $portal_settings['mail_smtp_port'] ?>" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="mail_smtp_auth" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('mail_smtp_auth') ?></label>
|
||||||
|
<div class="col-lg-2 col-md-2 col-sm-2">
|
||||||
|
<select id="mail_smtp_auth" name="mail_smtp_auth" class="form-control" required>
|
||||||
|
<option value="1" <?php echo ($portal_settings['mail_smtp_auth'] == 1) ? 'selected' : '' ?>>true</option>
|
||||||
|
<option value="0" <?php echo ($portal_settings['mail_smtp_auth'] == 0) ? 'selected' : '' ?>>false</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="mail_smtp_user" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('mail_smtp_user') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="mail_smtp_user" name="mail_smtp_user" value="<?php echo $portal_settings['mail_smtp_user'] ?>" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="mail_smtp_pass" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('mail_smtp_pass') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="password" class="form-control" id="mail_smtp_pass" name="mail_smtp_pass" value="*******************" placeholder="" autocomplete="new-password" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="card-footer py-4">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col d-flex justify-content-end">
|
||||||
|
<?php if ($API->checkPermissions('admin-mailsettings', 'RW', true)) { ?>
|
||||||
|
<button type="submit" class="btn btn-primary">
|
||||||
|
<i class="fas fa-edit"></i> <?php echo __('edit') ?>
|
||||||
|
</button>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
<?php if ($API->checkPermissions('admin-modules', 'RO', true)) { ?>
|
||||||
|
<div class="tab-pane fade show" id="modules" role="tabpanel" aria-labelledby="modules-tab">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-12">
|
||||||
|
<h2>
|
||||||
|
<i class="fa-solid fa-cubes"></i> <?php echo __('modules') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card p-3">
|
||||||
|
<form id="FormValidation" method="post" action="/api/v1/modules/">
|
||||||
|
<input type="hidden" name="portal_uuid" value="<?php echo $portal_settings['portal_uuid']; ?>">
|
||||||
|
<input type="hidden" name="_method" value="PUT">
|
||||||
|
<input type="hidden" name="_return" value="/systemconfig/#modules">
|
||||||
|
<table class="multi-filter-select display table table-striped table-hover" data-skip-columns="0,5">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('module_name') ?></th>
|
||||||
|
<th><?php echo __('enabled') ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th><?php echo __('module_name') ?></th>
|
||||||
|
<th><?php echo __('enabled') ?></th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
foreach ($system_modules as $module) { ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo $module['module_name'] ?> </td>
|
||||||
|
<td>
|
||||||
|
<label class="switch">
|
||||||
|
|
||||||
|
<input type="checkbox" class="checkbox" data-api-url="/api/v1/system/modules/" data-api-data='<?php echo json_encode(['module_uuid' => $module['module_uuid'], 'module_enabled' => $module['module_enabled'] ? 0 : 1]) ?>' data-api-changevalue="module_enabled"
|
||||||
|
<?php echo(($module['module_enabled']) ? 'checked' : '') ?>
|
||||||
|
<?php echo ($API->checkPermissions('admin-modules', 'RW', true)) ? '' : 'disabled' ?>
|
||||||
|
<?php echo(($module['module_slugify'] == 'system') ? 'disabled' : '') ?>>
|
||||||
|
<div class="slider"></div>
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<?php if ($API->checkPermissions('admin-sources', 'RO', true)) { ?>
|
||||||
|
<div class="tab-pane fade show" id="sources" role="tabpanel" aria-labelledby="sources-tab">
|
||||||
|
<div class="row mb-3">
|
||||||
|
<div class="col-12">
|
||||||
|
<h2>
|
||||||
|
<i class="fa-solid fa-cloud"></i> <?php echo __('sources') ?>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card p-3">
|
||||||
|
<div class="row row-cols-1 row-cols-md-3 g-4">
|
||||||
|
<div class="col">
|
||||||
|
<div class="card card-post card-round">
|
||||||
|
<img class="card-img-top" src="/src/images/sources/inserve/inserve_logo.webp" alt="Inserve Logo">
|
||||||
|
<div class="card-body">
|
||||||
|
<h3 class="card-title">
|
||||||
|
Inserve </h3>
|
||||||
|
<p class="card-text">
|
||||||
|
Inserve is Dutch software that helps MSPs support their customers in a personal and structured way. </p>
|
||||||
|
<a href="/system/sources/inserve" class="btn btn-primary">View</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
97
pub/bin/pages/system/sources/pageSourceInserve.php
Normal file
97
pub/bin/pages/system/sources/pageSourceInserve.php
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
use bin\php\Classes\pageNavbar;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# IDE Section
|
||||||
|
|
||||||
|
|
||||||
|
# Includes Section
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/bin/php/Classes/pageNavbar.php');
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
$API = new API();
|
||||||
|
$API->checkPermissions('admin-sources', 'RO');
|
||||||
|
|
||||||
|
# Page functions
|
||||||
|
|
||||||
|
|
||||||
|
# JS Scripts to load for this page
|
||||||
|
$jsScriptLoadData['activeTabOnRefresh'] = true;
|
||||||
|
$jsScriptLoadData['copyInputValue'] = true;
|
||||||
|
$jsScriptLoadData['updateToggle'] = true;
|
||||||
|
$jsScriptLoadData['breadCrumbs'] = true;
|
||||||
|
$jsScriptLoadData['inserve_source'] = true;
|
||||||
|
$jsScriptLoadData['validateJson'] = true;
|
||||||
|
|
||||||
|
# PageClasses Setup
|
||||||
|
$pageNavbar = new pageNavbar(true);
|
||||||
|
|
||||||
|
# Retrieve Information for the page
|
||||||
|
$inserve_settings = $GLOBALS['conn']->query("SELECT * FROM system_sources WHERE source_name = 'inserve'")->fetch_assoc();
|
||||||
|
|
||||||
|
# Set breadcrumb data
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('portal_management'), 'href' => '/systemconfig'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => __('sources'), 'href' => '/systemconfig#sources'));
|
||||||
|
array_push($GLOBALS['breadCrumbArray'], array('display' => 'Inserve', 'href' => ''));
|
||||||
|
|
||||||
|
|
||||||
|
# Start page output
|
||||||
|
$pageNavbar->outPutNavbar();
|
||||||
|
?>
|
||||||
|
<div class="card-body activeTabOnRefresh" style="opacity: 0; transition: opacity 10ms;">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 col-lg-12">
|
||||||
|
<div class="tab-content" id="v-pills-with-icon-tabContent">
|
||||||
|
<div class="card">
|
||||||
|
<div class="mx-2 pb-0 card-body">
|
||||||
|
<h1 class="">Inserve settings</h1>
|
||||||
|
<p>
|
||||||
|
Enter the necessary API details to set up and configure your connection to the Inserve API. This allows Sentri to communicate with Inserve and retrieve the data it needs. </p>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form id="FormValidation" method="post" action="/api/v1/system/sources/inserve/">
|
||||||
|
<input type="hidden" name="_method" value="POST">
|
||||||
|
<input type="hidden" name="_return" value="/system/sources/inserve">
|
||||||
|
<input type="hidden" name="source_name" value="inserve">
|
||||||
|
<div class="card-body">
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="source_url" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('inserve_url') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="source_url" name="source_url" value="<?php echo ($inserve_settings) ? $inserve_settings['source_url'] : '' ?>" placeholder="" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group form-show-validation row">
|
||||||
|
<label for="source_auth_token" class="col-lg-3 col-md-3 col-sm-4 mt-sm-2"><?php echo __('api_token') ?></label>
|
||||||
|
<div class="col-lg-9 col-md-12 col-sm-10">
|
||||||
|
<input type="text" class="form-control" id="source_auth_token" name="source_auth_token" value="" autocomplete="off" placeholder="<?php echo ($inserve_settings) ? substr($inserve_settings['source_auth_token'], 0, 6) . str_repeat('*', max(0, strlen($inserve_settings['source_auth_token']) - 6)) : ''; ?>" required/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer py-4">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col d-flex justify-content-end">
|
||||||
|
<button class="btn btn-success mx-2 test-inserve-connection-btn">
|
||||||
|
<i class="fa-solid fa-spell-check"></i> <?php echo __('test_connection') ?>
|
||||||
|
</button>
|
||||||
|
<?php if ($API->checkPermissions('admin-sources', 'RW', true)) { ?>
|
||||||
|
<button type="submit" class="btn btn-primary">
|
||||||
|
<i class="fa-solid fa-floppy-disk"></i> <?php echo __('save') ?>
|
||||||
|
</button>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
90
pub/bin/php/Classes/formBuilder.php
Normal file
90
pub/bin/php/Classes/formBuilder.php
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace bin\php\Classes;
|
||||||
|
class formBuilder
|
||||||
|
{
|
||||||
|
public $title;
|
||||||
|
public $icon;
|
||||||
|
public $submitButton;
|
||||||
|
public $closeButton;
|
||||||
|
public $closeButtonLocation;
|
||||||
|
|
||||||
|
public $submitButtonColor;
|
||||||
|
|
||||||
|
public $submitButtonText;
|
||||||
|
|
||||||
|
public $submitButtonIcon;
|
||||||
|
|
||||||
|
private $extraButtonsArray = array();
|
||||||
|
|
||||||
|
public function __construct($title, $icon, $closeButtonLocation, $submitButton = true, $closeButton = true)
|
||||||
|
{
|
||||||
|
$this->title = __($title);
|
||||||
|
$this->icon = $icon;
|
||||||
|
$this->submitButton = $submitButton;
|
||||||
|
$this->closeButton = $closeButton;
|
||||||
|
$this->closeButtonLocation = $closeButtonLocation;
|
||||||
|
$this->submitButtonColor = 'primary';
|
||||||
|
$this->submitButtonText = __($title);
|
||||||
|
$this->submitButtonIcon = $icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startForm()
|
||||||
|
{ ?>
|
||||||
|
<div class="row"><div class="col-md-8 ms-auto me-auto"><div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<h3><?php echo $this->icon ?> <?php echo $this->title ?></h3>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
|
||||||
|
public function endForm()
|
||||||
|
{ ?>
|
||||||
|
</div></div></div>
|
||||||
|
<?php }
|
||||||
|
|
||||||
|
# Add extra buttons to the form footer between the submit and close button
|
||||||
|
# Array example:
|
||||||
|
# array(
|
||||||
|
# 0 => array(
|
||||||
|
# 'buttonText' => 'testButton2123',
|
||||||
|
# 'buttonIcon' => 'ico123123ncontnet',
|
||||||
|
# 'buttonHref' => 'test'
|
||||||
|
# 'buttonColor' => 'success'
|
||||||
|
# ) > next array
|
||||||
|
|
||||||
|
public function addExtraButtons($extraButtonsArray)
|
||||||
|
{
|
||||||
|
foreach ($extraButtonsArray as $numb => $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);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function formFooter()
|
||||||
|
{ ?>
|
||||||
|
<div class="card-footer pt-3">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col d-flex justify-content-end">
|
||||||
|
<?php if ($this->submitButton) { ?>
|
||||||
|
<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) { ?>
|
||||||
|
<a href="<?php echo $extraButtonArray['buttonHref'] ?>" class="btn btn-<?php echo $extraButtonArray['buttonColor'] ?>"><?php echo $extraButtonArray['buttonIcon'] ?> <?php echo $extraButtonArray['buttonText'] ?></a>
|
||||||
|
<?php }
|
||||||
|
|
||||||
|
if ($this->closeButton) { ?>
|
||||||
|
<a href="<?php echo $this->closeButtonLocation ?>" class="btn btn-danger">
|
||||||
|
<i class="fas fa-times"></i> <?php echo __('close') ?>
|
||||||
|
</a>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
68
pub/bin/php/Classes/healthCheck.php
Normal file
68
pub/bin/php/Classes/healthCheck.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?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 vc_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
81
pub/bin/php/Classes/mailBuilder.php
Normal file
81
pub/bin/php/Classes/mailBuilder.php
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace bin\php\Classes;
|
||||||
|
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
|
require $_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
class mailBuilder
|
||||||
|
{
|
||||||
|
public $mail;
|
||||||
|
public $subject;
|
||||||
|
public $mailText;
|
||||||
|
|
||||||
|
private $portal_uuid;
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
$this->mail = new PHPMailer(true);
|
||||||
|
$sql = "SELECT mail_from_name,
|
||||||
|
mail_from_address,
|
||||||
|
mail_smtp_host,
|
||||||
|
mail_smtp_secure,
|
||||||
|
mail_smtp_port,
|
||||||
|
mail_smtp_auth,
|
||||||
|
mail_smtp_user,
|
||||||
|
mail_smtp_pass
|
||||||
|
FROM vc_portal_settings LIMIT 1";
|
||||||
|
$stmt = $GLOBALS['conn']->prepare($sql);
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
if ($result->num_rows > 0) {
|
||||||
|
$mail_settings = $result->fetch_assoc();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->mail->isSMTP();
|
||||||
|
$this->mail->Host = $mail_settings['mail_smtp_host'];
|
||||||
|
$this->mail->SMTPAuth = $mail_settings['mail_smtp_auth'];
|
||||||
|
$this->mail->Username = $mail_settings['mail_smtp_user'];
|
||||||
|
$this->mail->Password = $mail_settings['mail_smtp_pass'];
|
||||||
|
$this->mail->SMTPSecure = $mail_settings['mail_smtp_secure'];
|
||||||
|
$this->mail->Port = $mail_settings['mail_smtp_port'];
|
||||||
|
$this->mail->CharSet = 'UTF-8';
|
||||||
|
$this->mail->Encoding = 'base64';
|
||||||
|
|
||||||
|
$this->mail->setFrom($mail_settings['mail_from_address'], $mail_settings['mail_from_name']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function addAddress($address, $name)
|
||||||
|
{
|
||||||
|
$this->mail->addAddress($address, $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendMail()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->mail->isHTML(true);
|
||||||
|
$this->mail->Subject = $this->subject;
|
||||||
|
$this->mail->Body = $this->mailHtmlBody();
|
||||||
|
|
||||||
|
$this->mail->send();
|
||||||
|
return true;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mailHtmlBody()
|
||||||
|
{
|
||||||
|
$body = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/src/html/mailBody.html');
|
||||||
|
|
||||||
|
$bodyText = $this->mailText;
|
||||||
|
|
||||||
|
$body = str_replace('{{bodyText}}', $bodyText, $body);
|
||||||
|
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
}
|
||||||
518
pub/bin/php/Classes/pageBuilder.php
Normal file
518
pub/bin/php/Classes/pageBuilder.php
Normal file
@@ -0,0 +1,518 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace bin\php\Classes;
|
||||||
|
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
use api\classes\API;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
require_once($_SERVER['DOCUMENT_ROOT'] . '/api/classes/API.php');
|
||||||
|
|
||||||
|
class pageBuilder extends API
|
||||||
|
{
|
||||||
|
|
||||||
|
private $jsScriptLoadData;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
# retrieve all the pages from the database
|
||||||
|
$pages = [];
|
||||||
|
$query = "SELECT page_name, page_icon, page_description, page_location, page_url, page_color, module_name, module_slugify FROM system_pages
|
||||||
|
INNER JOIN system_modules ON system_pages.module_uuid = system_modules.module_uuid
|
||||||
|
WHERE system_modules.module_enabled = 1 ";
|
||||||
|
if ($stmt = $GLOBALS['conn']->prepare($query)) {
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$module = $row['module_slugify'];
|
||||||
|
$pages[$module][$row['page_name']] = $row;
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
$GLOBALS['pages'] = $pages;
|
||||||
|
|
||||||
|
$this->figureOutContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function figureOutContent()
|
||||||
|
{
|
||||||
|
$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) === '/') {
|
||||||
|
$requestUri = rtrim($requestUri, '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
$GLOBALS['breadCrumbArray'] = array(array('display' => '<i class="fas fa-home"></i>', 'href' => '/'));
|
||||||
|
|
||||||
|
$GLOBALS['pageContentToShow']['pageName'] = '404';
|
||||||
|
$GLOBALS['pageContentToShow']['pageFile'] = 'pageNotFound.php';
|
||||||
|
$GLOBALS['pageContentToShow']['pageIcon'] = '<i class="fa-solid fa-ban"></i>';
|
||||||
|
$GLOBALS['pageContentToShow']['noUsersAllowed'] = false;
|
||||||
|
|
||||||
|
foreach ($GLOBALS['pages'] as $module) {
|
||||||
|
foreach ($module as $page) {
|
||||||
|
if ($requestUri == $page['page_url']) {
|
||||||
|
$GLOBALS['pageContentToShow']['pageName'] = $page['page_name'];
|
||||||
|
$GLOBALS['pageContentToShow']['pageFile'] = $page['page_location'];
|
||||||
|
$GLOBALS['pageContentToShow']['pageIcon'] = '<i class="' . $page['page_icon'] . '"></i>';
|
||||||
|
$GLOBALS['pageContentToShow']['noUsersAllowed'] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildPage()
|
||||||
|
{ ?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<?php $this->pageHeadContent(); ?>
|
||||||
|
<body data-background-color="dark">
|
||||||
|
<div class="wrapper<?= (($_COOKIE['sidebarMinimized'] ?? '') === 'true' ? ' sidebar_minimize' : '') . (($_COOKIE['sidebarHovered'] ?? '') === 'true' ? ' sidebar_minimize_hover' : '') ?>">
|
||||||
|
<?php $this->pageSidebarContent(); ?>
|
||||||
|
<div class="main-panel">
|
||||||
|
<?php $this->pageNavbarContent() ?>
|
||||||
|
<div class="container">
|
||||||
|
<div class="page-inner">
|
||||||
|
<?php
|
||||||
|
include_once './bin/pages/' . $GLOBALS['pageContentToShow']['pageFile'];
|
||||||
|
if (isset($jsScriptLoadData)) {
|
||||||
|
$this->jsScriptLoadData = $jsScriptLoadData;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php $this->pageFooterContent() ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php $this->pageScriptContents(); ?>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<?php }
|
||||||
|
|
||||||
|
private
|
||||||
|
function pageHeadContent()
|
||||||
|
{ ?>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta content="width=device-width, initial-scale=1.0, shrink-to-fit=no" name="viewport"/>
|
||||||
|
<title>
|
||||||
|
<?php echo __($GLOBALS['pageContentToShow']['pageName']) ?>
|
||||||
|
</title>
|
||||||
|
|
||||||
|
<!-- Fonts and icons -->
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Public+Sans:300,400,500,600,700|Quicksand:300,400,500,600,700&display=swap" rel="stylesheet">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom-avatar {
|
||||||
|
width: 50px; /* Desired width */
|
||||||
|
height: 50px; /* Desired height */
|
||||||
|
display: inline-block; /* Ensure it behaves like an inline block */
|
||||||
|
background-size: cover; /* Stretch to cover the element */
|
||||||
|
background-position: center; /* Center the background image */
|
||||||
|
background-repeat: no-repeat; /* Prevent repetition */
|
||||||
|
border-radius: 50%; /* Circular shape */
|
||||||
|
overflow: hidden; /* Ensure no overflow for a clean circular look */
|
||||||
|
}
|
||||||
|
|
||||||
|
.flag-bg[data-flag="gb"] {
|
||||||
|
background-image: url('https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/6.6.6/flags/4x3/gb.svg'); /* Greece */
|
||||||
|
}
|
||||||
|
|
||||||
|
.flag-bg[data-flag="nl"] {
|
||||||
|
background-image: url('https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/6.6.6/flags/4x3/nl.svg'); /* Greece */
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataTables_filter {
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataTables_filter label {
|
||||||
|
width: 100%;
|
||||||
|
height: 40px;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataTables_filter input {
|
||||||
|
height: 40px;
|
||||||
|
width: 100% !important; /* Make the input field full width */
|
||||||
|
box-sizing: border-box; /* Ensure padding doesn't exceed the width */
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataTables_filter .fa-search {
|
||||||
|
position: absolute;
|
||||||
|
top: 12px;
|
||||||
|
left: auto;
|
||||||
|
right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataTables_length label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataTables_length label::before {
|
||||||
|
display: inline-block;
|
||||||
|
height: 40px;
|
||||||
|
padding-top: 10px; /* Move "Entries" down */
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataTables_length select {
|
||||||
|
flex: 1; /* Allow the select field to take the remaining space */
|
||||||
|
max-width: 100%; /* Ensure it doesn't exceed the container */
|
||||||
|
margin-left: 10px; /* Optional spacing between "Entries" and the select */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Change the border color of the entire dropdown options container */
|
||||||
|
.select2-container--bootstrap .select2-dropdown {
|
||||||
|
border: 0 solid rgba(80, 80, 80, 0.19) !important; /* Light gray border */
|
||||||
|
border-radius: 0.25rem; /* Optional: Add a border radius to match Bootstrap styles */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Optional: Remove white edges inside the dropdown */
|
||||||
|
.select2-container--bootstrap .select2-results {
|
||||||
|
padding: 0; /* Remove any extra padding inside the dropdown */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Change background color of selected items in the dropdown */
|
||||||
|
.select2-container--bootstrap .select2-results__option {
|
||||||
|
background-color: #282828 !important; /* Light green background */
|
||||||
|
color: #d5c4a1 !important; /* Dark green text */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Optional: Change border color on hover */
|
||||||
|
.select2-container--bootstrap .select2-results__option:hover {
|
||||||
|
background-color: #346b42 !important; /* Light blue background */
|
||||||
|
color: #d5c4a1 !important; /* Dark green text */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Change background color of selected items in the dropdown */
|
||||||
|
.select2-container--bootstrap .select2-results__option[aria-selected="true"] {
|
||||||
|
background-color: #1a3522 !important; /* Light green background */
|
||||||
|
color: #d5c4a1 !important; /* Dark green text */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Optional: Change the background color when hovering over selected items */
|
||||||
|
.select2-container--bootstrap .select2-results__option[aria-selected="true"]:hover {
|
||||||
|
background-color: #346b42 !important; /* Slightly darker green */
|
||||||
|
color: #d5c4a1 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Custom Slider switch (on/off button) */
|
||||||
|
|
||||||
|
|
||||||
|
</style>
|
||||||
|
<!-- CSS Files -->
|
||||||
|
<link rel="stylesheet" href="/src/css/bootstrap.gruvbox.min.css"/>
|
||||||
|
<link rel="stylesheet" href="/src/css/plugins.min.css"/>
|
||||||
|
<link rel="stylesheet" href="/src/css/kaiadmin.gruvbox.dark.css"/>
|
||||||
|
|
||||||
|
<!--<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lipis/flag-icons@7.2.3/css/flag-icons.min.css"/> -->
|
||||||
|
|
||||||
|
<!-- favicon -->
|
||||||
|
<link rel="icon" type="image/png" href="/src/images/favicon/favicon-96x96.png" sizes="96x96"/>
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/src/images/favicon/favicon-96x96.png"/>
|
||||||
|
<link rel="shortcut icon" href="/src/images/favicon/favicon.ico"/>
|
||||||
|
<link rel="apple-touch-icon" sizes="180x180" href="/src/images/favicon/apple-touch-icon.png"/>
|
||||||
|
<link rel="manifest" href="/src/images/favicon/site.webmanifest"/>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.fade-in {
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.3s ease, transform 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-in.show {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.transition-opacity {
|
||||||
|
transition: opacity 0.3s ease;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<?php }
|
||||||
|
|
||||||
|
private function pageSidebarContent()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
$API = new API();
|
||||||
|
function showSpan($module_name)
|
||||||
|
{
|
||||||
|
?>
|
||||||
|
<li class="nav-section">
|
||||||
|
<h4 class="text-section"><?php echo $module_name ?></h4>
|
||||||
|
</li>
|
||||||
|
<?php }
|
||||||
|
|
||||||
|
function showPage($module_name, $page_name)
|
||||||
|
{
|
||||||
|
$page = $GLOBALS['pages'][$module_name][$page_name];
|
||||||
|
?>
|
||||||
|
<li class="nav-item <?php echo($_SERVER['REQUEST_URI'] == $page['page_url'] ? 'active' : '') ?>">
|
||||||
|
<a href="<?php echo $page['page_url'] ?>">
|
||||||
|
<i class="<?php echo $page['page_icon'] ?>"></i> <?php echo __($page['page_name']) ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php } ?>
|
||||||
|
|
||||||
|
<div class="sidebar" data-background-color="dark">
|
||||||
|
<div class="sidebar-logo">
|
||||||
|
<div class="logo-header" data-background-color="dark2">
|
||||||
|
<a href="/" class="logo">
|
||||||
|
<img src="/src/images/logo-sidebar-dark.webp" alt="navbar brand" class="navbar-brand" height="50"/>
|
||||||
|
</a>
|
||||||
|
<div class="nav-toggle">
|
||||||
|
<button class="btn btn-toggle toggle-sidebar">
|
||||||
|
<i class="gg-menu-right"></i>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-toggle sidenav-toggler">
|
||||||
|
<i class="gg-menu-left"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<button class="topbar-toggler more">
|
||||||
|
<i class="gg-more-vertical-alt"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="sidebar-wrapper scrollbar scrollbar-inner">
|
||||||
|
<div class="sidebar-content">
|
||||||
|
<ul class="nav nav-secondary">
|
||||||
|
|
||||||
|
<?php
|
||||||
|
showPage('system', 'dashboard');
|
||||||
|
|
||||||
|
if ($GLOBALS['modules_enabled']['office'] && $API->checkPermissions('ofice-stompjes', 'RO', true)) {
|
||||||
|
showSpan('office');
|
||||||
|
showPage('office', 'stompjeslist');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($GLOBALS['modules_enabled']['servers'] && $API->checkPermissions('servers', 'RO', true)) {
|
||||||
|
showSpan('servers');
|
||||||
|
showPage('servers', 'server_overview');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($GLOBALS['modules_enabled']['customers'] && $API->checkPermissions('customer-companies', 'RO', true)) {
|
||||||
|
showSpan('customers');
|
||||||
|
showPage('customers', 'companies');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($GLOBALS['modules_enabled']['autop']) {
|
||||||
|
showSpan('autop');
|
||||||
|
showPage('autop', 'platforms');
|
||||||
|
showPage('autop', 'vendors');
|
||||||
|
showPage('autop', 'devices');
|
||||||
|
showPage('autop', 'provisioning');
|
||||||
|
showPage('autop', 'phonebooks');
|
||||||
|
showPage('autop', 'device_settings');
|
||||||
|
}
|
||||||
|
|
||||||
|
showSpan('system');
|
||||||
|
showPage('system', 'access_control');
|
||||||
|
showPage('system', 'systemconfig');
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
private
|
||||||
|
function pageNavbarContent()
|
||||||
|
{
|
||||||
|
?>
|
||||||
|
<div class="main-header">
|
||||||
|
<div class="main-header-logo">
|
||||||
|
<!-- Logo Header -->
|
||||||
|
<div class="logo-header" data-background-color="dark2">
|
||||||
|
<a href="/" class="logo">
|
||||||
|
<img src="/src/images/logo-sidebar-dark.webp" alt="navbar brand" class="navbar-brand" height="50"/>
|
||||||
|
</a>
|
||||||
|
<div class="nav-toggle">
|
||||||
|
<button class="btn btn-toggle toggle-sidebar">
|
||||||
|
<i class="gg-menu-right"></i>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-toggle sidenav-toggler">
|
||||||
|
<i class="gg-menu-left"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<button class="topbar-toggler more">
|
||||||
|
<i class="gg-more-vertical-alt"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<!-- End Logo Header -->
|
||||||
|
</div>
|
||||||
|
<!-- Navbar Header -->
|
||||||
|
<nav class="navbar navbar-header navbar-header-transparent navbar-expand-lg border-bottom" data-background-color="dark2">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<ul class="navbar-nav topbar-nav ms-md-auto align-items-center">
|
||||||
|
<li class="nav-item topbar-icon dropdown hidden-caret d-flex d-lg-none"></li>
|
||||||
|
|
||||||
|
<li class="nav-item topbar-user dropdown hidden-caret">
|
||||||
|
<a class="dropdown-toggle profile-pic" data-bs-toggle="dropdown" href="#" aria-expanded="false">
|
||||||
|
<div class="avatar-sm">
|
||||||
|
<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="..." class="avatar-img rounded-circle">
|
||||||
|
</div>
|
||||||
|
<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>
|
||||||
|
</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>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<!-- End Navbar -->
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
|
||||||
|
private
|
||||||
|
function pageFooterContent()
|
||||||
|
{ ?>
|
||||||
|
<footer class="footer py-2">
|
||||||
|
<div class="container-fluid d-flex justify-content-between">
|
||||||
|
<nav class="pull-left">
|
||||||
|
<ul class="nav">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="https://kb.sentri.digistate.nl" target="_blank"><i class="far fa-question-circle"></i> Help</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<div class="copyright">
|
||||||
|
<?php echo __('version') ?>
|
||||||
|
<a href="/changelog/">1.0</a>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="navbar-text">Sentri</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
<?php }
|
||||||
|
|
||||||
|
private
|
||||||
|
function pageScriptContents()
|
||||||
|
{ ?>
|
||||||
|
<!-- always load these -->
|
||||||
|
<script src="/src/js/core/jquery-3.7.1.min.js"></script>
|
||||||
|
<script src="/src/js/core/popper.min.js"></script>
|
||||||
|
<script src="/src/js/core/bootstrap.min.js"></script>
|
||||||
|
|
||||||
|
<!-- Bootstrap Notify -->
|
||||||
|
<script src="/src/js/plugin/bootstrap-notify/bootstrap-notify.min.js"></script>
|
||||||
|
|
||||||
|
<!-- Sweet Alert -->
|
||||||
|
<script src="/src/js/plugin/sweetalert2/sweetalert2.min.js"></script>
|
||||||
|
|
||||||
|
<!-- Kaiadmin JS -->
|
||||||
|
<script src="/src/js/kaiadmin.dark.min.js"></script>
|
||||||
|
|
||||||
|
<!-- jQuery Scrollbar -->
|
||||||
|
<script src="/src/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js"></script>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Chart JS
|
||||||
|
<script src="/src/js/plugin/chart.js/chart.min.js"></script>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- jQuery Sparkline
|
||||||
|
<script src="/src/js/plugin/jquery.sparkline/jquery.sparkline.min.js"></script>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Chart Circle
|
||||||
|
<script src="/src/js/plugin/chart-circle/circles.min.js"></script>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- jQuery Vector Maps
|
||||||
|
<script src="/src/js/plugin/jsvectormap/jsvectormap.min.js"></script>
|
||||||
|
<script src="/src/js/plugin/jsvectormap/world.js"></script>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<?php
|
||||||
|
# keeps refreshing the timeZoneCookie
|
||||||
|
setTimeZoneCookie();
|
||||||
|
|
||||||
|
if (isset($this->jsScriptLoadData)) {
|
||||||
|
include_once $_SERVER['DOCUMENT_ROOT'] . '/bin/php/jsScripts.php';
|
||||||
|
}
|
||||||
|
# process response from actions
|
||||||
|
if (isset($_SESSION['response'])) {
|
||||||
|
$ar = json_decode($_SESSION['response']);
|
||||||
|
$type = key($ar);
|
||||||
|
$text = reset($ar);
|
||||||
|
$title = $type;
|
||||||
|
if ($type == 'error') {
|
||||||
|
$type = 'danger';
|
||||||
|
}
|
||||||
|
unset($_SESSION['response']) ?>
|
||||||
|
<script>
|
||||||
|
var content = {};
|
||||||
|
content.message = '<?php echo __($text) ?>';
|
||||||
|
content.title = '<?php echo ucfirst($title) ?>';
|
||||||
|
content.icon = "fa fa-bell";
|
||||||
|
|
||||||
|
$.notify(content, {
|
||||||
|
type: '<?php echo $type ?>',
|
||||||
|
placement: {
|
||||||
|
from: 'top',
|
||||||
|
align: 'right',
|
||||||
|
},
|
||||||
|
time: 10,
|
||||||
|
delay: 3,
|
||||||
|
});
|
||||||
|
$('#multiple').select2({
|
||||||
|
theme: "bootstrap"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
|
}
|
||||||
47
pub/bin/php/Classes/pageNavbar.php
Normal file
47
pub/bin/php/Classes/pageNavbar.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace bin\php\Classes;
|
||||||
|
if (!defined('APP_INIT')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
class pageNavbar
|
||||||
|
{
|
||||||
|
public $breadCrumb;
|
||||||
|
private $buttons = array();
|
||||||
|
|
||||||
|
public function __construct($showBreadCrumb, $title = false)
|
||||||
|
{
|
||||||
|
$this->breadCrumb = $showBreadCrumb;
|
||||||
|
$this->title = $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function AddHTMLButton($html)
|
||||||
|
{
|
||||||
|
array_push($this->buttons, $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function outPutNavbar()
|
||||||
|
{
|
||||||
|
?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col d-flex justify-content-start">
|
||||||
|
<?php if ($this->breadCrumb) { ?>
|
||||||
|
<div class="pb-2" id="breadCrumb"></div>
|
||||||
|
<?php } elseif ($this->title) { ?>
|
||||||
|
<h2 class="px-4 mb-0"><?php echo $this->title ?></h2>
|
||||||
|
<?php } else { ?>
|
||||||
|
<div></div>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
<div class="col d-flex justify-content-end">
|
||||||
|
<?php if (count($this->buttons)) {
|
||||||
|
foreach ($this->buttons as $button) {
|
||||||
|
echo $button;
|
||||||
|
}
|
||||||
|
} ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
117
pub/bin/php/Functions/globalFunctions.php
Normal file
117
pub/bin/php/Functions/globalFunctions.php
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
function setResponse($type, $text)
|
||||||
|
{
|
||||||
|
$value = json_encode([$type => $text]);
|
||||||
|
$_SESSION['response'] = $value;
|
||||||
|
header('location: ' . $_SERVER['HTTP_REFERER']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkIfUser()
|
||||||
|
{
|
||||||
|
if ($_SESSION['user']['user_group_type'] == 'user') {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showTime($timestamp)
|
||||||
|
{
|
||||||
|
if (empty($timestamp)) {
|
||||||
|
echo __('never');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dt = new DateTime("@$timestamp");
|
||||||
|
$dt->setTimezone(new DateTimeZone($_SESSION['user']['user_timezone']));
|
||||||
|
|
||||||
|
echo $dt->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function human_filesize($bytes, $decimals = 2)
|
||||||
|
{
|
||||||
|
$sizes = ['B', 'K', 'M', 'G', 'T', 'P']; // Array instead of string
|
||||||
|
$factor = floor((strlen($bytes) - 1) / 3);
|
||||||
|
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $sizes[$factor];
|
||||||
|
}
|
||||||
|
|
||||||
|
function retrieveAvailableLocales()
|
||||||
|
{
|
||||||
|
$availableLocales = array();
|
||||||
|
$localeDir = $_SERVER['DOCUMENT_ROOT'] . "/bin/locales/";
|
||||||
|
|
||||||
|
$localesInDir = array_diff(scandir($localeDir), array('.', '..'));
|
||||||
|
foreach ($localesInDir as $localeFile) {
|
||||||
|
if (pathinfo($localeFile, PATHINFO_EXTENSION) === 'php') {
|
||||||
|
$availableLocales[] = basename($localeFile, '.php'); // Strip .php extension
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $availableLocales;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPreferredLocale()
|
||||||
|
|
||||||
|
{
|
||||||
|
$availableLocales = retrieveAvailableLocales();
|
||||||
|
$defaultLocale = 'en';
|
||||||
|
|
||||||
|
$selectedLocale = in_array($_SESSION['user']['user_pref_language'], $availableLocales)
|
||||||
|
? $_SESSION['user']['user_pref_language']
|
||||||
|
: $defaultLocale;
|
||||||
|
return $selectedLocale;
|
||||||
|
}
|
||||||
|
|
||||||
|
function __(string $key, array $replacements = [])
|
||||||
|
{
|
||||||
|
global $translations;
|
||||||
|
|
||||||
|
$translation = $translations[$key] ?? $key;
|
||||||
|
|
||||||
|
// Replace placeholders with dynamic values
|
||||||
|
foreach ($replacements as $placeholder => $value) {
|
||||||
|
$translation = str_replace(":{$placeholder}", $value, $translation);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $translation;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_enabled_platforms($conn)
|
||||||
|
{
|
||||||
|
$platforms_enabled = [];
|
||||||
|
$query = "SELECT * FROM vc_platforms WHERE platform_enabled = 1";
|
||||||
|
|
||||||
|
if ($stmt = $conn->prepare($query)) {
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$platforms_enabled[$row['platform_uuid']] = [
|
||||||
|
'data' => $row,
|
||||||
|
'default_template_uuid' => false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
return $platforms_enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEnabledModules()
|
||||||
|
{
|
||||||
|
$modules_enabled = [];
|
||||||
|
$query = "SELECT * FROM system_modules";
|
||||||
|
|
||||||
|
if ($stmt = $GLOBALS['conn']->prepare($query)) {
|
||||||
|
$stmt->execute();
|
||||||
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
|
while ($row = $result->fetch_assoc()) {
|
||||||
|
$modules_enabled[$row['module_slugify']] = $row['module_enabled'];
|
||||||
|
}
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
return $modules_enabled;
|
||||||
|
|
||||||
|
}
|
||||||
28
pub/bin/php/db_connect.php
Normal file
28
pub/bin/php/db_connect.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
/** @var TYPE_NAME $db_server */
|
||||||
|
/** @var TYPE_NAME $db_user */
|
||||||
|
/** @var TYPE_NAME $db_password */
|
||||||
|
/** @var TYPE_NAME $db_database */
|
||||||
|
/** @var TYPE_NAME $db_port */
|
||||||
|
|
||||||
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/config.php');
|
||||||
|
$GLOBALS['conn'] = mysqli_connect($db_server, $db_user, $db_password, $db_database, $db_port);
|
||||||
|
if (!$GLOBALS['conn']) {
|
||||||
|
echo "Fout bij verbinden met de database" . PHP_EOL;
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$dsn = "mysql:host=$db_server;dbname=$db_database;port=$db_port;charset=utf8mb4";
|
||||||
|
$username = $db_user;
|
||||||
|
$password = $db_password;
|
||||||
|
|
||||||
|
$GLOBALS['pdo'] = new PDO($dsn, $username, $password, [
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // Throw exceptions on errors
|
||||||
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // Fetch associative arrays by default
|
||||||
|
PDO::ATTR_EMULATE_PREPARES => false, // Use real prepared statements
|
||||||
|
]);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Fout bij verbinden met de database: " . $e->getMessage() . PHP_EOL;
|
||||||
|
die();
|
||||||
|
}
|
||||||
1321
pub/bin/php/jsScripts.php
Normal file
1321
pub/bin/php/jsScripts.php
Normal file
File diff suppressed because it is too large
Load Diff
23
pub/config-sample.php
Normal file
23
pub/config-sample.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is used for connecting to the database and configuring the superuser password
|
||||||
|
* Rename this file to config.php to make it take effect
|
||||||
|
*/
|
||||||
|
|
||||||
|
# The superuser password (login name is superuser)
|
||||||
|
$superuserpassword = "changethispassword!";
|
||||||
|
|
||||||
|
# database server name
|
||||||
|
$db_server = "localhost";
|
||||||
|
|
||||||
|
# database server port (default = 3306)
|
||||||
|
$db_port = "3306";
|
||||||
|
|
||||||
|
# database name
|
||||||
|
$db_database = "db";
|
||||||
|
|
||||||
|
# database user
|
||||||
|
$db_user = "db-user";
|
||||||
|
|
||||||
|
# Database password
|
||||||
|
$db_password = "db-password";
|
||||||
19
pub/data/customxml/_global/softkey/CallFailed.xml
Normal file
19
pub/data/customxml/_global/softkey/CallFailed.xml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<CallFailed>
|
||||||
|
<Disable>
|
||||||
|
<Key Type="Switch" />
|
||||||
|
<Key Type="End Call"/>
|
||||||
|
</Disable>
|
||||||
|
<Enable>
|
||||||
|
<Key Type="NewCall"/>
|
||||||
|
<Key Type="Empty"/>
|
||||||
|
<Key Type="Empty"/>
|
||||||
|
<Key Type="Empty"/>
|
||||||
|
</Enable>
|
||||||
|
<Default>
|
||||||
|
<Key Type="NewCall"/>
|
||||||
|
<Key Type="Empty"/>
|
||||||
|
<Key Type="Empty"/>
|
||||||
|
<Key Type="Empty"/>
|
||||||
|
</Default>
|
||||||
|
</CallFailed>
|
||||||
20
pub/data/customxml/_global/softkey/CallIn.xml
Normal file
20
pub/data/customxml/_global/softkey/CallIn.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<CallIn>
|
||||||
|
<Disable>
|
||||||
|
<Key Type="Empty"/>
|
||||||
|
<Key Type="Switch"/>
|
||||||
|
<Key Type="Decline"/>
|
||||||
|
</Disable>
|
||||||
|
<Enable>
|
||||||
|
<Key Type="Answer"/>
|
||||||
|
<Key Type="Forward"/>
|
||||||
|
<Key Type="Silence"/>
|
||||||
|
<Key Type="Reject"/>
|
||||||
|
</Enable>
|
||||||
|
<Default>
|
||||||
|
<Key Type="Answer"/>
|
||||||
|
<Key Type="Forward"/>
|
||||||
|
<Key Type="Silence"/>
|
||||||
|
<Key Type="Reject"/>
|
||||||
|
</Default>
|
||||||
|
</CallIn>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user