mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-08-15 23:08:44 +02:00
Merge branch 'ent-12019-api-2-0' into 'develop'
new api 2.0 See merge request artica/pandorafms!6845
This commit is contained in:
commit
44ae109889
BIN
pandora_console/api/documentation/favicon-16x16.png
Normal file
BIN
pandora_console/api/documentation/favicon-16x16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
BIN
pandora_console/api/documentation/favicon-32x32.png
Normal file
BIN
pandora_console/api/documentation/favicon-32x32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
16
pandora_console/api/documentation/index.css
Normal file
16
pandora_console/api/documentation/index.css
Normal file
@ -0,0 +1,16 @@
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: #fafafa;
|
||||
}
|
29
pandora_console/api/documentation/index.html
Normal file
29
pandora_console/api/documentation/index.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!-- HTML for static distribution bundle build -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Pandora FMS: API documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
|
||||
<link rel="stylesheet" type="text/css" href="index.css" />
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/png"
|
||||
href="./favicon-32x32.png"
|
||||
sizes="32x32"
|
||||
/>
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/png"
|
||||
href="./favicon-16x16.png"
|
||||
sizes="16x16"
|
||||
/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
<script src="./swagger-ui-bundle.js" charset="UTF-8"></script>
|
||||
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"></script>
|
||||
<script src="./swagger-initializer.js" charset="UTF-8"></script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,96 @@
|
||||
ramda: 361.78 KB (5.92%)
|
||||
ramda-adjunct: 257.62 KB (4.21%)
|
||||
lodash: 253.56 KB (4.15%)
|
||||
autolinker: 203.32 KB (3.33%)
|
||||
@swagger-api/apidom-ns-openapi-3-0: 201.95 KB (3.30%)
|
||||
swagger-client: 172.85 KB (2.83%)
|
||||
cookie: 5.16 KB (2.98%)
|
||||
is-plain-object: 758 B (0.428%)
|
||||
<self>: 166.96 KB (96.6%)
|
||||
@swagger-api/apidom-ns-openapi-3-1: 153.37 KB (2.51%)
|
||||
immutable: 139.01 KB (2.27%)
|
||||
react-dom: 129.98 KB (2.13%)
|
||||
remarkable: 125.56 KB (2.05%)
|
||||
highlight.js: 111.85 KB (1.83%)
|
||||
js-yaml: 105.01 KB (1.72%)
|
||||
readable-stream: 96.66 KB (1.58%)
|
||||
@swagger-api/apidom-reference: 90.42 KB (1.48%)
|
||||
core-js-pure: 82.79 KB (1.35%)
|
||||
dompurify: 63.43 KB (1.04%)
|
||||
minim: 57.35 KB (0.938%)
|
||||
buffer: 56.99 KB (0.932%)
|
||||
@swagger-api/apidom-ns-json-schema-draft-4: 54.24 KB (0.887%)
|
||||
@swagger-api/apidom-core: 50.31 KB (0.823%)
|
||||
@swagger-api/apidom-ast: 47.25 KB (0.773%)
|
||||
react-syntax-highlighter: 40.15 KB (0.657%)
|
||||
react-redux: 36.88 KB (0.603%)
|
||||
fast-json-patch: 31.89 KB (0.522%)
|
||||
qs: 26.61 KB (0.435%)
|
||||
reselect: 21.43 KB (0.350%)
|
||||
short-unique-id: 18.88 KB (0.309%)
|
||||
sha.js: 18.57 KB (0.304%)
|
||||
object-inspect: 18.44 KB (0.302%)
|
||||
redux: 16.37 KB (0.268%)
|
||||
url-parse: 16.23 KB (0.266%)
|
||||
tslib: 15.87 KB (0.260%)
|
||||
events: 14.54 KB (0.238%)
|
||||
get-intrinsic: 13.01 KB (0.213%)
|
||||
zenscroll: 12.31 KB (0.201%)
|
||||
react-debounce-input: 11.95 KB (0.195%)
|
||||
react-immutable-proptypes: 11.82 KB (0.193%)
|
||||
ret: 10.82 KB (0.177%)
|
||||
lodash.debounce: 10.53 KB (0.172%)
|
||||
unraw: 9.9 KB (0.162%)
|
||||
string_decoder: 9.24 KB (0.151%)
|
||||
xml: 7.39 KB (0.121%)
|
||||
react-copy-to-clipboard: 7.33 KB (0.120%)
|
||||
traverse: 7.15 KB (0.117%)
|
||||
react: 6.94 KB (0.113%)
|
||||
@swagger-api/apidom-json-pointer: 6.39 KB (0.105%)
|
||||
randexp: 6.15 KB (0.101%)
|
||||
react-immutable-pure-component: 6.01 KB (0.0982%)
|
||||
redux-immutable: 5.43 KB (0.0889%)
|
||||
process: 5.29 KB (0.0865%)
|
||||
drange: 4.8 KB (0.0786%)
|
||||
lowlight: 4.42 KB (0.0724%)
|
||||
scheduler: 4.33 KB (0.0708%)
|
||||
@babel/runtime: 4.23 KB (0.0691%)
|
||||
deep-extend: 4.19 KB (0.0686%)
|
||||
deepmerge: 3.95 KB (0.0647%)
|
||||
base64-js: 3.84 KB (0.0628%)
|
||||
stream-browserify: 3.76 KB (0.0615%)
|
||||
@swagger-api/apidom-error: 3.36 KB (0.0549%)
|
||||
side-channel: 3.31 KB (0.0542%)
|
||||
copy-to-clipboard: 3.29 KB (0.0537%)
|
||||
format: 3.26 KB (0.0533%)
|
||||
stampit: 3.16 KB (0.0516%)
|
||||
css.escape: 3.08 KB (0.0504%)
|
||||
serialize-error: 2.93 KB (0.0479%)
|
||||
define-data-property: 2.77 KB (0.0453%)
|
||||
prop-types: 2.6 KB (0.0425%)
|
||||
querystringify: 2.5 KB (0.0410%)
|
||||
xml-but-prettier: 2.17 KB (0.0354%)
|
||||
has-symbols: 2.13 KB (0.0348%)
|
||||
function-bind: 2.12 KB (0.0346%)
|
||||
ieee754: 2.1 KB (0.0344%)
|
||||
@braintree/sanitize-url: 1.98 KB (0.0324%)
|
||||
safe-buffer: 1.63 KB (0.0267%)
|
||||
call-bind: 1.59 KB (0.0260%)
|
||||
util-deprecate: 1.58 KB (0.0258%)
|
||||
randombytes: 1.54 KB (0.0252%)
|
||||
js-file-download: 1.52 KB (0.0248%)
|
||||
classnames: 1.49 KB (0.0244%)
|
||||
use-sync-external-store: 1.28 KB (0.0210%)
|
||||
repeat-string: 1.18 KB (0.0194%)
|
||||
set-function-length: 1.14 KB (0.0187%)
|
||||
@babel/runtime-corejs3: 878 B (0.0140%)
|
||||
has-property-descriptors: 817 B (0.0130%)
|
||||
toggle-selection: 780 B (0.0125%)
|
||||
inherits: 753 B (0.0120%)
|
||||
requires-port: 753 B (0.0120%)
|
||||
fault: 691 B (0.0110%)
|
||||
gopd: 263 B (0.00420%)
|
||||
hasown: 234 B (0.00374%)
|
||||
has-proto: 197 B (0.00315%)
|
||||
object-inspect|.: 15 B (0.000240%)
|
||||
<self>: 2.72 MB (45.5%)
|
@ -0,0 +1,14 @@
|
||||
readable-stream: 96.66 KB (6.16%)
|
||||
buffer: 56.99 KB (3.63%)
|
||||
sha.js: 18.57 KB (1.18%)
|
||||
events: 14.54 KB (0.926%)
|
||||
string_decoder: 9.24 KB (0.589%)
|
||||
xml: 7.39 KB (0.471%)
|
||||
process: 5.29 KB (0.337%)
|
||||
deep-extend: 4.19 KB (0.267%)
|
||||
stream-browserify: 3.76 KB (0.239%)
|
||||
safe-buffer: 1.63 KB (0.104%)
|
||||
util-deprecate: 1.58 KB (0.100%)
|
||||
randombytes: 1.54 KB (0.0981%)
|
||||
inherits: 753 B (0.0468%)
|
||||
<self>: 1.32 MB (85.9%)
|
@ -0,0 +1,96 @@
|
||||
ramda: 361.78 KB (5.92%)
|
||||
ramda-adjunct: 257.62 KB (4.21%)
|
||||
lodash: 253.56 KB (4.15%)
|
||||
autolinker: 203.32 KB (3.33%)
|
||||
@swagger-api/apidom-ns-openapi-3-0: 201.95 KB (3.30%)
|
||||
swagger-client: 172.85 KB (2.83%)
|
||||
cookie: 5.16 KB (2.98%)
|
||||
is-plain-object: 758 B (0.428%)
|
||||
<self>: 166.96 KB (96.6%)
|
||||
@swagger-api/apidom-ns-openapi-3-1: 153.37 KB (2.51%)
|
||||
immutable: 139.01 KB (2.27%)
|
||||
react-dom: 129.98 KB (2.13%)
|
||||
remarkable: 125.56 KB (2.05%)
|
||||
highlight.js: 111.85 KB (1.83%)
|
||||
js-yaml: 105.01 KB (1.72%)
|
||||
readable-stream: 96.66 KB (1.58%)
|
||||
@swagger-api/apidom-reference: 90.42 KB (1.48%)
|
||||
core-js-pure: 82.79 KB (1.35%)
|
||||
dompurify: 63.43 KB (1.04%)
|
||||
minim: 57.35 KB (0.938%)
|
||||
buffer: 56.99 KB (0.932%)
|
||||
@swagger-api/apidom-ns-json-schema-draft-4: 54.24 KB (0.887%)
|
||||
@swagger-api/apidom-core: 50.31 KB (0.823%)
|
||||
@swagger-api/apidom-ast: 47.25 KB (0.773%)
|
||||
react-syntax-highlighter: 40.15 KB (0.657%)
|
||||
react-redux: 36.88 KB (0.603%)
|
||||
fast-json-patch: 31.89 KB (0.522%)
|
||||
qs: 26.61 KB (0.435%)
|
||||
reselect: 21.43 KB (0.350%)
|
||||
short-unique-id: 18.88 KB (0.309%)
|
||||
sha.js: 18.57 KB (0.304%)
|
||||
object-inspect: 18.44 KB (0.302%)
|
||||
redux: 16.37 KB (0.268%)
|
||||
url-parse: 16.23 KB (0.266%)
|
||||
tslib: 15.87 KB (0.260%)
|
||||
events: 14.54 KB (0.238%)
|
||||
get-intrinsic: 13.01 KB (0.213%)
|
||||
zenscroll: 12.31 KB (0.201%)
|
||||
react-debounce-input: 11.95 KB (0.195%)
|
||||
react-immutable-proptypes: 11.82 KB (0.193%)
|
||||
ret: 10.82 KB (0.177%)
|
||||
lodash.debounce: 10.53 KB (0.172%)
|
||||
unraw: 9.9 KB (0.162%)
|
||||
string_decoder: 9.24 KB (0.151%)
|
||||
xml: 7.39 KB (0.121%)
|
||||
react-copy-to-clipboard: 7.33 KB (0.120%)
|
||||
traverse: 7.15 KB (0.117%)
|
||||
react: 6.94 KB (0.113%)
|
||||
@swagger-api/apidom-json-pointer: 6.39 KB (0.105%)
|
||||
randexp: 6.15 KB (0.101%)
|
||||
react-immutable-pure-component: 6.01 KB (0.0982%)
|
||||
redux-immutable: 5.43 KB (0.0889%)
|
||||
process: 5.29 KB (0.0865%)
|
||||
drange: 4.8 KB (0.0786%)
|
||||
lowlight: 4.42 KB (0.0724%)
|
||||
scheduler: 4.33 KB (0.0708%)
|
||||
@babel/runtime: 4.23 KB (0.0691%)
|
||||
deep-extend: 4.19 KB (0.0686%)
|
||||
deepmerge: 3.95 KB (0.0647%)
|
||||
base64-js: 3.84 KB (0.0628%)
|
||||
stream-browserify: 3.76 KB (0.0615%)
|
||||
@swagger-api/apidom-error: 3.36 KB (0.0549%)
|
||||
side-channel: 3.31 KB (0.0542%)
|
||||
copy-to-clipboard: 3.29 KB (0.0537%)
|
||||
format: 3.26 KB (0.0533%)
|
||||
stampit: 3.16 KB (0.0516%)
|
||||
css.escape: 3.08 KB (0.0504%)
|
||||
serialize-error: 2.93 KB (0.0479%)
|
||||
define-data-property: 2.77 KB (0.0453%)
|
||||
prop-types: 2.6 KB (0.0425%)
|
||||
querystringify: 2.5 KB (0.0410%)
|
||||
xml-but-prettier: 2.17 KB (0.0354%)
|
||||
has-symbols: 2.13 KB (0.0348%)
|
||||
function-bind: 2.12 KB (0.0346%)
|
||||
ieee754: 2.1 KB (0.0344%)
|
||||
@braintree/sanitize-url: 1.98 KB (0.0324%)
|
||||
safe-buffer: 1.63 KB (0.0267%)
|
||||
call-bind: 1.59 KB (0.0260%)
|
||||
util-deprecate: 1.58 KB (0.0258%)
|
||||
randombytes: 1.54 KB (0.0252%)
|
||||
js-file-download: 1.52 KB (0.0248%)
|
||||
classnames: 1.49 KB (0.0244%)
|
||||
use-sync-external-store: 1.28 KB (0.0210%)
|
||||
repeat-string: 1.18 KB (0.0194%)
|
||||
set-function-length: 1.14 KB (0.0187%)
|
||||
@babel/runtime-corejs3: 878 B (0.0140%)
|
||||
has-property-descriptors: 817 B (0.0130%)
|
||||
toggle-selection: 780 B (0.0125%)
|
||||
inherits: 753 B (0.0120%)
|
||||
requires-port: 753 B (0.0120%)
|
||||
fault: 691 B (0.0110%)
|
||||
gopd: 263 B (0.00420%)
|
||||
hasown: 234 B (0.00374%)
|
||||
has-proto: 197 B (0.00315%)
|
||||
object-inspect|.: 15 B (0.000240%)
|
||||
<self>: 2.72 MB (45.5%)
|
95
pandora_console/api/documentation/oauth2-redirect.html
Normal file
95
pandora_console/api/documentation/oauth2-redirect.html
Normal file
@ -0,0 +1,95 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<title>Swagger UI: OAuth2 Redirect</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
"use strict";
|
||||
function run() {
|
||||
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
||||
var sentState = oauth2.state;
|
||||
var redirectUrl = oauth2.redirectUrl;
|
||||
var isValid, qp, arr;
|
||||
|
||||
if (/code|token|error/.test(window.location.hash)) {
|
||||
qp = window.location.hash.substring(1).replace("?", "&");
|
||||
} else {
|
||||
qp = location.search.substring(1);
|
||||
}
|
||||
|
||||
arr = qp.split("&");
|
||||
arr.forEach(function(v, i, _arr) {
|
||||
_arr[i] = '"' + v.replace("=", '":"') + '"';
|
||||
});
|
||||
qp = qp
|
||||
? JSON.parse("{" + arr.join() + "}", function(key, value) {
|
||||
return key === "" ? value : decodeURIComponent(value);
|
||||
})
|
||||
: {};
|
||||
|
||||
isValid = qp.state === sentState;
|
||||
|
||||
if (
|
||||
(oauth2.auth.schema.get("flow") === "accessCode" ||
|
||||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
|
||||
oauth2.auth.schema.get("flow") === "authorization_code") &&
|
||||
!oauth2.auth.code
|
||||
) {
|
||||
if (!isValid) {
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "warning",
|
||||
message:
|
||||
"Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
|
||||
});
|
||||
}
|
||||
|
||||
if (qp.code) {
|
||||
delete oauth2.state;
|
||||
oauth2.auth.code = qp.code;
|
||||
oauth2.callback({ auth: oauth2.auth, redirectUrl: redirectUrl });
|
||||
} else {
|
||||
let oauthErrorMsg;
|
||||
if (qp.error) {
|
||||
oauthErrorMsg =
|
||||
"[" +
|
||||
qp.error +
|
||||
"]: " +
|
||||
(qp.error_description
|
||||
? qp.error_description + ". "
|
||||
: "no accessCode received from the server. ") +
|
||||
(qp.error_uri ? "More info: " + qp.error_uri : "");
|
||||
}
|
||||
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "error",
|
||||
message:
|
||||
oauthErrorMsg ||
|
||||
"[Authorization failed]: no accessCode received from the server."
|
||||
});
|
||||
}
|
||||
} else {
|
||||
oauth2.callback({
|
||||
auth: oauth2.auth,
|
||||
token: qp,
|
||||
isValid: isValid,
|
||||
redirectUrl: redirectUrl
|
||||
});
|
||||
}
|
||||
window.close();
|
||||
}
|
||||
|
||||
if (document.readyState !== "loading") {
|
||||
run();
|
||||
} else {
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
run();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
41
pandora_console/api/documentation/swagger-initializer.js
Normal file
41
pandora_console/api/documentation/swagger-initializer.js
Normal file
@ -0,0 +1,41 @@
|
||||
window.onload = function() {
|
||||
//<editor-fold desc="Changeable Configuration Block">
|
||||
const UrlMutatorPlugin = system => ({
|
||||
rootInjects: {
|
||||
setServer: server => {
|
||||
const jsonSpec = system.getState().toJSON().spec.json;
|
||||
const endpoint = window.location.pathname.replace(
|
||||
"/api/documentation/",
|
||||
""
|
||||
);
|
||||
const servers = [
|
||||
{
|
||||
url: endpoint + jsonSpec.servers[0].url,
|
||||
description: "Pandora Fms Api"
|
||||
}
|
||||
];
|
||||
const newJsonSpec = Object.assign({}, jsonSpec, { servers });
|
||||
|
||||
return system.specActions.updateJsonSpec(newJsonSpec);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "../v1/swagger.json",
|
||||
dom_id: "#swagger-ui",
|
||||
docExpansion: "none",
|
||||
deepLinking: true,
|
||||
presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
|
||||
plugins: [SwaggerUIBundle.plugins.DownloadUrl, UrlMutatorPlugin],
|
||||
layout: "StandaloneLayout",
|
||||
onComplete: () => {
|
||||
window.ui.setServer();
|
||||
}
|
||||
});
|
||||
|
||||
window.ui = ui;
|
||||
|
||||
//</editor-fold>
|
||||
};
|
81546
pandora_console/api/documentation/swagger-ui-bundle.js
Normal file
81546
pandora_console/api/documentation/swagger-ui-bundle.js
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,120 @@
|
||||
/*!
|
||||
Copyright (c) 2018 Jed Watson.
|
||||
Licensed under the MIT License (MIT), see
|
||||
http://jedwatson.github.io/classnames
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @description Recursive object extending
|
||||
* @author Viacheslav Lotsmanov <lotsmanov89@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2018 Viacheslav Lotsmanov
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* The buffer module from node.js, for the browser.
|
||||
*
|
||||
* @author Feross Aboukhadijeh <https://feross.org>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* cookie
|
||||
* Copyright(c) 2012-2014 Roman Shtylman
|
||||
* Copyright(c) 2015 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2021 Joachim Wester
|
||||
* MIT license
|
||||
*/
|
||||
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2022 Joachim Wester
|
||||
* MIT licensed
|
||||
*/
|
||||
|
||||
/*!
|
||||
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
||||
*
|
||||
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* repeat-string <https://github.com/jonschlinkert/repeat-string>
|
||||
*
|
||||
* Copyright (c) 2014-2015, Jon Schlinkert.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/*! @license DOMPurify 3.0.8 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.8/LICENSE */
|
||||
|
||||
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
|
||||
/*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
|
||||
|
||||
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* react-dom.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* react.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* scheduler.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* use-sync-external-store-with-selector.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
File diff suppressed because one or more lines are too long
23906
pandora_console/api/documentation/swagger-ui-es-bundle-core.js
Normal file
23906
pandora_console/api/documentation/swagger-ui-es-bundle-core.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,35 @@
|
||||
/*!
|
||||
* @description Recursive object extending
|
||||
* @author Viacheslav Lotsmanov <lotsmanov89@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2018 Viacheslav Lotsmanov
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* The buffer module from node.js, for the browser.
|
||||
*
|
||||
* @author Feross Aboukhadijeh <https://feross.org>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
File diff suppressed because one or more lines are too long
79500
pandora_console/api/documentation/swagger-ui-es-bundle.js
Normal file
79500
pandora_console/api/documentation/swagger-ui-es-bundle.js
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,120 @@
|
||||
/*!
|
||||
Copyright (c) 2018 Jed Watson.
|
||||
Licensed under the MIT License (MIT), see
|
||||
http://jedwatson.github.io/classnames
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @description Recursive object extending
|
||||
* @author Viacheslav Lotsmanov <lotsmanov89@gmail.com>
|
||||
* @license MIT
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2018 Viacheslav Lotsmanov
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* The buffer module from node.js, for the browser.
|
||||
*
|
||||
* @author Feross Aboukhadijeh <https://feross.org>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* cookie
|
||||
* Copyright(c) 2012-2014 Roman Shtylman
|
||||
* Copyright(c) 2015 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2021 Joachim Wester
|
||||
* MIT license
|
||||
*/
|
||||
|
||||
/*!
|
||||
* https://github.com/Starcounter-Jack/JSON-Patch
|
||||
* (c) 2017-2022 Joachim Wester
|
||||
* MIT licensed
|
||||
*/
|
||||
|
||||
/*!
|
||||
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
||||
*
|
||||
* Copyright (c) 2014-2017, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* repeat-string <https://github.com/jonschlinkert/repeat-string>
|
||||
*
|
||||
* Copyright (c) 2014-2015, Jon Schlinkert.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/*! @license DOMPurify 3.0.8 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.8/LICENSE */
|
||||
|
||||
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
|
||||
/*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
|
||||
|
||||
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* react-dom.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* react.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* scheduler.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* use-sync-external-store-with-selector.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
File diff suppressed because one or more lines are too long
13181
pandora_console/api/documentation/swagger-ui-standalone-preset.js
Normal file
13181
pandora_console/api/documentation/swagger-ui-standalone-preset.js
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,22 @@
|
||||
/*!
|
||||
* The buffer module from node.js, for the browser.
|
||||
*
|
||||
* @author Feross Aboukhadijeh <https://feross.org>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
|
||||
/*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
|
||||
|
||||
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
|
||||
/**
|
||||
* @license React
|
||||
* react.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
File diff suppressed because one or more lines are too long
9303
pandora_console/api/documentation/swagger-ui.css
Normal file
9303
pandora_console/api/documentation/swagger-ui.css
Normal file
File diff suppressed because it is too large
Load Diff
1
pandora_console/api/documentation/swagger-ui.css.map
Normal file
1
pandora_console/api/documentation/swagger-ui.css.map
Normal file
File diff suppressed because one or more lines are too long
18272
pandora_console/api/documentation/swagger-ui.js
Normal file
18272
pandora_console/api/documentation/swagger-ui.js
Normal file
File diff suppressed because it is too large
Load Diff
1
pandora_console/api/documentation/swagger-ui.js.map
Normal file
1
pandora_console/api/documentation/swagger-ui.js.map
Normal file
File diff suppressed because one or more lines are too long
1
pandora_console/api/index.html
Normal file
1
pandora_console/api/index.html
Normal file
@ -0,0 +1 @@
|
||||
<meta http-equiv="REFRESH" content="0; url=documentation" />
|
5
pandora_console/api/v1/.htaccess
Normal file
5
pandora_console/api/v1/.htaccess
Normal file
@ -0,0 +1,5 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
RewriteRule ^$ public/ [L]
|
||||
RewriteRule (.*) public/$1 [L]
|
||||
</IfModule>
|
25
pandora_console/api/v1/config/bootstrap.php
Normal file
25
pandora_console/api/v1/config/bootstrap.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use DI\ContainerBuilder;
|
||||
use Slim\App;
|
||||
|
||||
require_once __DIR__.'/includeDependencies.php';
|
||||
|
||||
$containerBuilder = new ContainerBuilder();
|
||||
|
||||
// Add DI container definitions.
|
||||
$containerBuilder->addDefinitions(__DIR__.'/container.php');
|
||||
|
||||
// Create DI container instance.
|
||||
$container = $containerBuilder->build();
|
||||
|
||||
// Create Slim App instance.
|
||||
$app = $container->get(App::class);
|
||||
|
||||
// Set attachment directory.
|
||||
$config['attachment_directory'] = __DIR__.'/../../../attachment';
|
||||
|
||||
// Register routes.
|
||||
(require __DIR__.'/routes.php')($app);
|
||||
|
||||
return $app;
|
57
pandora_console/api/v1/config/container.php
Normal file
57
pandora_console/api/v1/config/container.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Repositories\TokenRepository;
|
||||
use PandoraFMS\Modules\Authentication\Repositories\TokenRepositoryMySQL;
|
||||
use PandoraFMS\Modules\Events\Repositories\EventRepository;
|
||||
use PandoraFMS\Modules\Events\Repositories\EventRepositoryMySQL;
|
||||
use PandoraFMS\Modules\Groups\Repositories\GroupRepository;
|
||||
use PandoraFMS\Modules\Groups\Repositories\GroupRepositoryMySQL;
|
||||
use PandoraFMS\Modules\Shared\Repositories\Repository;
|
||||
use PandoraFMS\Modules\Shared\Repositories\RepositoryMySQL;
|
||||
use PandoraFMS\Modules\Users\Repositories\UserRepository;
|
||||
use PandoraFMS\Modules\Users\Repositories\UserRepositoryMySQL;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Slim\App;
|
||||
use Slim\Factory\AppFactory;
|
||||
|
||||
return [
|
||||
'settings' => function () {
|
||||
return include __DIR__.'/settings.php';
|
||||
},
|
||||
App::class => function (ContainerInterface $container) {
|
||||
AppFactory::setContainer($container);
|
||||
|
||||
$app = AppFactory::create();
|
||||
|
||||
$basePath = rtrim(
|
||||
preg_replace(
|
||||
'/(.*)public\/.*/',
|
||||
'$1',
|
||||
$_SERVER['SCRIPT_NAME']
|
||||
),
|
||||
'/'
|
||||
);
|
||||
|
||||
$app->setBasePath($basePath);
|
||||
|
||||
// Register middleware.
|
||||
(include __DIR__.'/middleware.php')($app, $container);
|
||||
|
||||
return $app;
|
||||
},
|
||||
Repository::class => function (ContainerInterface $container) {
|
||||
return $container->get(RepositoryMySQL::class);
|
||||
},
|
||||
TokenRepository::class => function (ContainerInterface $container) {
|
||||
return $container->get(TokenRepositoryMySQL::class);
|
||||
},
|
||||
UserRepository::class => function (ContainerInterface $container) {
|
||||
return $container->get(UserRepositoryMySQL::class);
|
||||
},
|
||||
GroupRepository::class => function (ContainerInterface $container) {
|
||||
return $container->get(GroupRepositoryMySQL::class);
|
||||
},
|
||||
EventRepository::class => function (ContainerInterface $container) {
|
||||
return $container->get(EventRepositoryMySQL::class);
|
||||
},
|
||||
];
|
20
pandora_console/api/v1/config/generateDoc.php
Normal file
20
pandora_console/api/v1/config/generateDoc.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../../../vendor/autoload.php';
|
||||
|
||||
$exclude = ['tests'];
|
||||
$pattern = '*.php';
|
||||
|
||||
$openapi = \OpenApi\Generator::scan(
|
||||
\OpenApi\Util::finder(
|
||||
[
|
||||
__DIR__.'/..',
|
||||
__DIR__.'/../../../include/lib/Modules',
|
||||
],
|
||||
$exclude,
|
||||
$pattern
|
||||
)
|
||||
);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
file_put_contents(__DIR__.'/../public/swagger.json', $openapi->toJson());
|
4
pandora_console/api/v1/config/includeDependencies.php
Normal file
4
pandora_console/api/v1/config/includeDependencies.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../../../vendor/autoload.php';
|
||||
require_once __DIR__.'/../../../include/config.php';
|
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
global $config;
|
||||
|
||||
ob_start();
|
||||
if (file_exists($config['homedir'].'/'.ENTERPRISE_DIR.'/load_enterprise.php') === true) {
|
||||
$config['return_api_mode'] = true;
|
||||
include_once $config['homedir'].'/'.ENTERPRISE_DIR.'/load_enterprise.php';
|
||||
include_once $config['homedir'].'/'.ENTERPRISE_DIR.'/include/functions_login.php';
|
||||
}
|
||||
|
||||
$error = ob_get_clean();
|
||||
if (empty($error) === false) {
|
||||
throw new Exception($error);
|
||||
}
|
99
pandora_console/api/v1/config/middleware.php
Normal file
99
pandora_console/api/v1/config/middleware.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum;
|
||||
use PandoraFMS\Modules\Shared\Middlewares\AclListMiddleware;
|
||||
use PandoraFMS\Modules\Shared\Middlewares\UserTokenMiddleware;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Slim\App;
|
||||
|
||||
return function (App $app, ContainerInterface $container) {
|
||||
// Parse json, form data and xml.
|
||||
$app->addBodyParsingMiddleware();
|
||||
|
||||
// Add the Slim built-in routing middleware.
|
||||
$app->addRoutingMiddleware();
|
||||
|
||||
// Authenticate Integria.
|
||||
$beforeMiddleware = function (
|
||||
Request $request,
|
||||
RequestHandler $handler
|
||||
) use (
|
||||
$app,
|
||||
$container
|
||||
) {
|
||||
$ipOrigin = $_SERVER['REMOTE_ADDR'];
|
||||
$aclListMiddleware = $container->get(AclListMiddleware::class);
|
||||
if ($aclListMiddleware->check($ipOrigin) === false) {
|
||||
$response = $app->getResponseFactory()->createResponse();
|
||||
$response->getBody()->write(
|
||||
json_encode(['error' => __('IP %s is not in ACL list', $ipOrigin)])
|
||||
);
|
||||
|
||||
$errorCode = HttpCodesEnum::UNAUTHORIZED;
|
||||
$newResponse = $response->withStatus($errorCode);
|
||||
return $newResponse;
|
||||
}
|
||||
|
||||
$userTokenMiddleware = $container->get(UserTokenMiddleware::class);
|
||||
if ($userTokenMiddleware->check($request) === false) {
|
||||
$response = $app->getResponseFactory()->createResponse();
|
||||
$response->getBody()->write(
|
||||
json_encode(['error' => __('You need to be authenticated to perform this action')])
|
||||
);
|
||||
|
||||
$errorCode = HttpCodesEnum::UNAUTHORIZED;
|
||||
$newResponse = $response->withStatus($errorCode);
|
||||
return $newResponse;
|
||||
}
|
||||
|
||||
try {
|
||||
include_once __DIR__.'/includeEnterpriseDependencies.php';
|
||||
} catch (\Throwable $th) {
|
||||
$response = $app->getResponseFactory()->createResponse();
|
||||
$response->getBody()->write(
|
||||
json_encode(['error' => __('Invalid License')])
|
||||
);
|
||||
|
||||
$errorCode = HttpCodesEnum::UNAUTHORIZED;
|
||||
$newResponse = $response->withStatus($errorCode);
|
||||
return $newResponse;
|
||||
}
|
||||
|
||||
$response = $handler->handle($request);
|
||||
return $response;
|
||||
};
|
||||
|
||||
$app->add($beforeMiddleware);
|
||||
|
||||
// Handle exceptions.
|
||||
// Define Custom Error Handler.
|
||||
$customErrorHandler = function (
|
||||
Request $request,
|
||||
Throwable $exception,
|
||||
bool $displayErrorDetails,
|
||||
bool $logErrors,
|
||||
bool $logErrorDetails,
|
||||
?LoggerInterface $logger=null
|
||||
) use ($app) {
|
||||
$logger?->error($exception->getMessage());
|
||||
$response = $app->getResponseFactory()->createResponse();
|
||||
$response->getBody()->write(
|
||||
json_encode(['error' => $exception->getMessage()])
|
||||
);
|
||||
|
||||
$errorCode = 500;
|
||||
if (empty($exception->getCode()) === false) {
|
||||
$errorCode = $exception->getCode();
|
||||
}
|
||||
|
||||
$newResponse = $response->withStatus($errorCode);
|
||||
return $newResponse;
|
||||
};
|
||||
|
||||
// Add Error Middleware.
|
||||
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
|
||||
$errorMiddleware->setDefaultErrorHandler($customErrorHandler);
|
||||
};
|
12
pandora_console/api/v1/config/routes.php
Normal file
12
pandora_console/api/v1/config/routes.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Slim\App;
|
||||
|
||||
return function (App $app) {
|
||||
(include __DIR__.'/../../../include/lib/Modules/Authentication/routes.php')($app);
|
||||
(include __DIR__.'/../../../include/lib/Modules/Events/routes.php')($app);
|
||||
(include __DIR__.'/../../../include/lib/Modules/Groups/routes.php')($app);
|
||||
(include __DIR__.'/../../../include/lib/Modules/Profiles/routes.php')($app);
|
||||
(include __DIR__.'/../../../include/lib/Modules/Tags/routes.php')($app);
|
||||
(include __DIR__.'/../../../include/lib/Modules/Users/routes.php')($app);
|
||||
};
|
10
pandora_console/api/v1/config/settings.php
Normal file
10
pandora_console/api/v1/config/settings.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/../../../include/config.php';
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('log_errors', 1);
|
||||
ini_set('error_log', $config['homedir'].'/log/console.log');
|
||||
|
||||
return [];
|
7
pandora_console/api/v1/public/.htaccess
Normal file
7
pandora_console/api/v1/public/.htaccess
Normal file
@ -0,0 +1,7 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^ index.php [QSA,L]
|
||||
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
|
||||
</IfModule>
|
3
pandora_console/api/v1/public/index.php
Normal file
3
pandora_console/api/v1/public/index.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
(require __DIR__.'/../config/bootstrap.php')->run();
|
3802
pandora_console/api/v1/public/swagger.json
Normal file
3802
pandora_console/api/v1/public/swagger.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,7 @@
|
||||
],
|
||||
"config": {
|
||||
"platform": {
|
||||
"php": "8.0.2"
|
||||
"php": "8.2"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
@ -18,7 +18,17 @@
|
||||
"amphp/parallel-functions": "^1.0",
|
||||
"chrome-php/chrome": "^1.8.1",
|
||||
"artica/phpchartjs": "^1.0",
|
||||
"tinymce/tinymce": "^6.4"
|
||||
"tinymce/tinymce": "^6.4",
|
||||
"slim/slim": "4.*",
|
||||
"slim/psr7": "^1.6",
|
||||
"nyholm/psr7": "^1.8",
|
||||
"nyholm/psr7-server": "^1.1",
|
||||
"guzzlehttp/psr7": "^2",
|
||||
"laminas/laminas-diactoros": "^3.2",
|
||||
"php-di/php-di": "^7.0",
|
||||
"zircote/swagger-php": "^4.8",
|
||||
"doctrine/annotations": "^2.0",
|
||||
"ramsey/uuid": "^4.7"
|
||||
},
|
||||
"repositories": {
|
||||
"phpchartjs": {
|
||||
|
2120
pandora_console/composer.lock
generated
2120
pandora_console/composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,17 @@
|
||||
START TRANSACTION;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ttoken` (
|
||||
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`label` TEXT NOT NULL,
|
||||
`uuid` TEXT NOT NULL,
|
||||
`challenge` TEXT NOT NULL,
|
||||
`id_user` varchar(60) NOT NULL default '',
|
||||
`validity` datetime,
|
||||
`last_usage` datetime,
|
||||
PRIMARY KEY(`id`),
|
||||
FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE
|
||||
) ENGINE = InnoDB DEFAULT CHARSET=UTF8MB4;
|
||||
|
||||
-- Watch out! The following field migration must be done before altering the corresponding table.
|
||||
UPDATE `tevent_filter`
|
||||
SET `search` = `regex`,
|
||||
|
@ -253,6 +253,11 @@ if ($access_console_node === true) {
|
||||
$sub['godmode/users/profile_list']['id'] = 'Profile_management';
|
||||
}
|
||||
|
||||
if ((bool) check_acl($config['id_user'], 0, 'PM') === true) {
|
||||
$sub['godmode/users/token_list']['text'] = __('Token management');
|
||||
$sub['godmode/users/token_list']['id'] = 'token_management';
|
||||
}
|
||||
|
||||
if (empty($sub) === false) {
|
||||
$menu_godmode['gusuarios']['sub'] = $sub;
|
||||
$menu_godmode['gusuarios']['text'] = __('Profiles');
|
||||
|
@ -44,57 +44,9 @@ $new_profile = (bool) get_parameter('new_profile');
|
||||
$id_profile = (int) get_parameter('id');
|
||||
// Header.
|
||||
if (is_metaconsole() === false) {
|
||||
$buttons = [
|
||||
'user' => [
|
||||
'active' => false,
|
||||
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/user_list&tab=user&pure='.$pure.'">'.html_print_image(
|
||||
'images/user.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('User management'),
|
||||
'class' => 'invert_filter main_menu_icon',
|
||||
]
|
||||
).'</a>',
|
||||
],
|
||||
'profile' => [
|
||||
'active' => false,
|
||||
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/profile_list&tab=profile&pure='.$pure.'">'.html_print_image(
|
||||
'images/suitcase@svg.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('Profile management'),
|
||||
'class' => 'invert_filter main_menu_icon',
|
||||
]
|
||||
).'</a>',
|
||||
],
|
||||
];
|
||||
|
||||
$buttons[$tab]['active'] = true;
|
||||
|
||||
$profile = db_get_row('tperfil', 'id_perfil', $id_profile);
|
||||
|
||||
ui_print_standard_header(
|
||||
__('Edit profile %s', $profile['name']),
|
||||
'images/user.svg',
|
||||
false,
|
||||
'configure_profiles_tab',
|
||||
true,
|
||||
$buttons,
|
||||
[
|
||||
[
|
||||
'link' => '',
|
||||
'label' => __('Profiles'),
|
||||
],
|
||||
[
|
||||
'link' => '',
|
||||
'label' => __('Manage users'),
|
||||
],
|
||||
[
|
||||
'link' => ui_get_full_url('index.php?sec=gusuarios&sec2=godmode/users/profile_list&tab=profile'),
|
||||
'label' => __('User Profile management'),
|
||||
],
|
||||
]
|
||||
);
|
||||
$title = __('Edit profile %s', $profile['name']);
|
||||
user_print_header($pure, $tab, $title);
|
||||
$sec2 = 'gusuarios';
|
||||
} else {
|
||||
user_meta_print_header();
|
||||
|
204
pandora_console/godmode/users/configure_token.php
Normal file
204
pandora_console/godmode/users/configure_token.php
Normal file
@ -0,0 +1,204 @@
|
||||
<?php
|
||||
/**
|
||||
* Configure Token.
|
||||
*
|
||||
* @category Users
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
*
|
||||
* Pandora FMS - https://pandorafms.com
|
||||
* ==================================================
|
||||
* Copyright (c) 2005-2024 Pandora FMS
|
||||
* Please see https://pandorafms.com/community/ for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
// Global variables.
|
||||
global $config;
|
||||
|
||||
check_login();
|
||||
|
||||
require_once $config['homedir'].'/include/functions_token.php';
|
||||
|
||||
enterprise_include_once('meta/include/functions_users_meta.php');
|
||||
|
||||
// Get parameters.
|
||||
$tab = get_parameter('tab', 'token');
|
||||
$pure = get_parameter('pure', 0);
|
||||
$id_token = (int) get_parameter('id_token');
|
||||
|
||||
// Header.
|
||||
if (is_metaconsole() === false) {
|
||||
user_print_header($pure, $tab);
|
||||
$sec2 = 'gusuarios';
|
||||
} else {
|
||||
user_meta_print_header();
|
||||
$sec2 = 'advanced';
|
||||
}
|
||||
|
||||
$url_list = 'index.php?sec='.$sec;
|
||||
$url_list .= '&sec2=godmode/users/token_list';
|
||||
$url_list .= '&pure='.$pure;
|
||||
|
||||
// Edit token.
|
||||
if (empty($id_token) === true) {
|
||||
$label = '';
|
||||
$validity = '';
|
||||
$page_title = __('Create token');
|
||||
} else {
|
||||
try {
|
||||
$token = get_user_token($id_token);
|
||||
} catch (\Exception $e) {
|
||||
ui_print_error_message(
|
||||
__('There was a problem get token, %s', $e->getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$table = new StdClass();
|
||||
$table->width = '100%';
|
||||
$table->class = 'databox filters';
|
||||
$table->data = [];
|
||||
$table->rowspan = [];
|
||||
$table->colspan = [];
|
||||
|
||||
$table->data[0][0] = __('Token label');
|
||||
$table->data[0][1] = html_print_input_text(
|
||||
'label',
|
||||
$token['label'],
|
||||
'',
|
||||
50,
|
||||
255,
|
||||
true
|
||||
);
|
||||
|
||||
if ((bool) users_is_admin() === true) {
|
||||
$table->data[0][2] = __('User');
|
||||
$user_users = users_get_user_users(
|
||||
$config['id_user'],
|
||||
'AR',
|
||||
true
|
||||
);
|
||||
|
||||
$table->data[0][3] = html_print_select(
|
||||
$user_users,
|
||||
'idUser',
|
||||
$config['id_user'],
|
||||
'',
|
||||
'',
|
||||
0,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
$expiration_date = null;
|
||||
$expiration_time = null;
|
||||
if (empty($token['validity']) === false) {
|
||||
$array_date = explode(' ', io_safe_output($token['validity']));
|
||||
if (is_array($array_date) === true) {
|
||||
$expiration_date = $array_date[0];
|
||||
if (isset($array_date[1]) === true
|
||||
&& empty($array_date[1]) === false
|
||||
) {
|
||||
$expiration_time = $array_date[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$table->data[1][0] = __('Expiration');
|
||||
$table->data[1][1] = html_print_input_text(
|
||||
'date-expiration',
|
||||
$expiration_date,
|
||||
'',
|
||||
50,
|
||||
255,
|
||||
true
|
||||
);
|
||||
|
||||
$table->data[1][2] = __('Expiration Time');
|
||||
$table->data[1][3] = html_print_input_text(
|
||||
'time-expiration',
|
||||
$expiration_time,
|
||||
'',
|
||||
50,
|
||||
255,
|
||||
true
|
||||
);
|
||||
|
||||
echo '<form class="max_floating_element_size" method="post" action="'.$url_list.'">';
|
||||
|
||||
html_print_table($table);
|
||||
|
||||
$actionButtons = [];
|
||||
|
||||
if (empty($id_token) === true) {
|
||||
$actionButtons[] = html_print_submit_button(
|
||||
__('Create'),
|
||||
'crt',
|
||||
false,
|
||||
['icon' => 'wand'],
|
||||
true
|
||||
);
|
||||
html_print_input_hidden('create_token', 1);
|
||||
} else {
|
||||
$actionButtons[] = html_print_submit_button(
|
||||
__('Update'),
|
||||
'upd',
|
||||
false,
|
||||
['icon' => 'update'],
|
||||
true
|
||||
);
|
||||
|
||||
html_print_input_hidden('id_token', $id_token);
|
||||
html_print_input_hidden('update_token', 1);
|
||||
}
|
||||
|
||||
$actionButtons[] = html_print_go_back_button(
|
||||
ui_get_full_url($url_list),
|
||||
['button_class' => ''],
|
||||
true
|
||||
);
|
||||
|
||||
html_print_action_buttons(
|
||||
implode('', $actionButtons),
|
||||
['type' => 'form_action']
|
||||
);
|
||||
|
||||
echo '</form>';
|
||||
|
||||
ui_include_time_picker();
|
||||
ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript/i18n/');
|
||||
|
||||
?>
|
||||
|
||||
<script type="text/javascript" language="javascript">
|
||||
$(document).ready (function () {
|
||||
$('#text-date-expiration').datepicker({
|
||||
dateFormat: 'yy-mm-dd',
|
||||
changeMonth: true,
|
||||
changeYear: true,
|
||||
showAnim: 'slideDown'
|
||||
});
|
||||
|
||||
$('[id^=text-time-expiration]').timepicker({
|
||||
showSecond: true,
|
||||
timeFormat: '<?php echo TIME_FORMAT_JS; ?>',
|
||||
timeOnlyTitle: '<?php echo __('Choose time'); ?>',
|
||||
timeText: '<?php echo __('Time'); ?>',
|
||||
hourText: '<?php echo __('Hour'); ?>',
|
||||
minuteText: '<?php echo __('Minute'); ?>',
|
||||
secondText: '<?php echo __('Second'); ?>',
|
||||
currentText: '<?php echo __('Now'); ?>',
|
||||
closeText: '<?php echo __('Close'); ?>'
|
||||
});
|
||||
});
|
||||
</script>
|
@ -246,60 +246,9 @@ if (is_metaconsole() === true) {
|
||||
user_meta_print_header();
|
||||
$sec = 'advanced';
|
||||
} else {
|
||||
if ((bool) check_acl($config['id_user'], 0, 'UM') === false) {
|
||||
$buttons = [];
|
||||
} else {
|
||||
$buttons = [
|
||||
'user' => [
|
||||
'active' => false,
|
||||
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/user_list&tab=user&pure='.$pure.'">'.html_print_image(
|
||||
'images/user.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('User management'),
|
||||
'class' => 'invert_filter main_menu_icon',
|
||||
]
|
||||
).'</a>',
|
||||
],
|
||||
'profile' => [
|
||||
'active' => false,
|
||||
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/profile_list&tab=profile&pure='.$pure.'">'.html_print_image(
|
||||
'images/suitcase@svg.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('Profile management'),
|
||||
'class' => 'invert_filter main_menu_icon',
|
||||
]
|
||||
).'</a>',
|
||||
],
|
||||
];
|
||||
$buttons[$tab]['active'] = true;
|
||||
}
|
||||
|
||||
$edit_user = get_parameter('edit_user');
|
||||
|
||||
ui_print_standard_header(
|
||||
($edit_user) ? sprintf('%s [ %s ]', __('Update User'), $id) : __('Create User'),
|
||||
'images/gm_users.png',
|
||||
false,
|
||||
'',
|
||||
true,
|
||||
$buttons,
|
||||
[
|
||||
[
|
||||
'link' => '',
|
||||
'label' => __('Profiles'),
|
||||
],
|
||||
[
|
||||
'link' => ui_get_full_url('index.php?sec=gusuarios&sec2=godmode/users/user_list'),
|
||||
'label' => __('Manage users'),
|
||||
],
|
||||
[
|
||||
'link' => '',
|
||||
'label' => __('User Detail Editor'),
|
||||
],
|
||||
]
|
||||
);
|
||||
$title = ($edit_user) ? sprintf('%s [ %s ]', __('Update User'), $id) : __('Create User');
|
||||
user_print_header($pure, $tab, $title);
|
||||
$sec = 'gusuarios';
|
||||
}
|
||||
|
||||
|
@ -51,52 +51,7 @@ $pure = get_parameter('pure', 0);
|
||||
|
||||
// Header.
|
||||
if (is_metaconsole() === false) {
|
||||
$buttons = [
|
||||
'user' => [
|
||||
'active' => false,
|
||||
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/user_list&tab=user&pure='.$pure.'">'.html_print_image(
|
||||
'images/user.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('User management'),
|
||||
'class' => 'invert_filter main_menu_user',
|
||||
]
|
||||
).'</a>',
|
||||
],
|
||||
'profile' => [
|
||||
'active' => false,
|
||||
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/profile_list&tab=profile&pure='.$pure.'">'.html_print_image(
|
||||
'images/suitcase@svg.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('Profile management'),
|
||||
'class' => 'invert_filter main_menu_user',
|
||||
]
|
||||
).'</a>',
|
||||
],
|
||||
];
|
||||
|
||||
$buttons[$tab]['active'] = true;
|
||||
|
||||
// Header.
|
||||
ui_print_standard_header(
|
||||
__('User Profile management'),
|
||||
'images/user.svg',
|
||||
false,
|
||||
'profile_tab',
|
||||
false,
|
||||
$buttons,
|
||||
[
|
||||
[
|
||||
'link' => '',
|
||||
'label' => __('Profiles'),
|
||||
],
|
||||
[
|
||||
'link' => '',
|
||||
'label' => __('Manage users'),
|
||||
],
|
||||
]
|
||||
);
|
||||
user_print_header($pure, $tab);
|
||||
$sec = 'gusuarios';
|
||||
} else {
|
||||
user_meta_print_header();
|
||||
|
214
pandora_console/godmode/users/token_list.php
Normal file
214
pandora_console/godmode/users/token_list.php
Normal file
@ -0,0 +1,214 @@
|
||||
<?php
|
||||
/**
|
||||
* Tokens.
|
||||
*
|
||||
* @category Users
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2024 Pandora FMS
|
||||
* Please see https://pandorafms.com/community/ for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Load global vars.
|
||||
global $config;
|
||||
|
||||
check_login();
|
||||
|
||||
require_once $config['homedir'].'/include/functions_token.php';
|
||||
require_once $config['homedir'].'/include/functions_users.php';
|
||||
|
||||
enterprise_include_once('meta/include/functions_users_meta.php');
|
||||
|
||||
$tab = get_parameter('tab', 'token');
|
||||
$pure = get_parameter('pure', 0);
|
||||
|
||||
// Header.
|
||||
if (is_metaconsole() === false) {
|
||||
user_print_header($pure, $tab);
|
||||
$sec = 'gusuarios';
|
||||
} else {
|
||||
user_meta_print_header();
|
||||
$sec = 'advanced';
|
||||
}
|
||||
|
||||
$edit_url = 'index.php?sec='.$sec;
|
||||
$edit_url .= '&sec2=godmode/users/configure_token';
|
||||
$edit_url .= '&pure='.$pure;
|
||||
|
||||
$delete_token = (bool) get_parameter('delete_token');
|
||||
$create_token = (bool) get_parameter('create_token');
|
||||
$update_token = (bool) get_parameter('update_token');
|
||||
$id_token = (int) get_parameter('id_token');
|
||||
|
||||
// Token deletion.
|
||||
if ($delete_token === true) {
|
||||
try {
|
||||
delete_user_token($id_token);
|
||||
ui_print_success_message(__('Successfully deleted'));
|
||||
} catch (\Exception $e) {
|
||||
ui_print_error_message(
|
||||
__('There was a problem deleting token, %s', $e->getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$tokenMsg = '';
|
||||
if ($create_token === true || $update_token === true) {
|
||||
$label = get_parameter('label', null);
|
||||
$idUser = get_parameter('idUser', $config['id_user']);
|
||||
|
||||
$expirationDate = get_parameter('date-expiration', null);
|
||||
$expirationTime = get_parameter('time-expiration', null);
|
||||
$validity = null;
|
||||
if (empty($expirationDate) === false) {
|
||||
$validity = $expirationDate;
|
||||
if (empty($expirationTime) === false) {
|
||||
$validity .= ' '.$expirationTime;
|
||||
}
|
||||
}
|
||||
|
||||
$values = [
|
||||
'idUser' => $idUser,
|
||||
'label' => $label,
|
||||
'validity' => $validity,
|
||||
];
|
||||
|
||||
// Create token.
|
||||
if ($create_token === true) {
|
||||
try {
|
||||
$token = create_user_token($values);
|
||||
$smgInfo = __('This code will appear only once, please keep it in a safe place');
|
||||
$smgInfo .= '.</br>';
|
||||
$smgInfo .= __('If you lose the code, you will only able to delete it and create a new one');
|
||||
$smgInfo .= '.</br></br>';
|
||||
$smgInfo .= '<i>';
|
||||
$smgInfo .= $token['token'];
|
||||
$smgInfo .= '</i>';
|
||||
$tokenMsg = ui_print_info_message($smgInfo, '', true);
|
||||
ui_print_success_message(__('Successfully created'));
|
||||
} catch (\Exception $e) {
|
||||
ui_print_error_message(
|
||||
__('There was a problem creating this token, %s', $e->getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Update token.
|
||||
if ($update_token === true) {
|
||||
try {
|
||||
$token = update_user_token($id_token, $values);
|
||||
ui_print_success_message(__('Successfully updated'));
|
||||
} catch (\Exception $e) {
|
||||
ui_print_error_message(
|
||||
__('There was a problem updating this token, %s', $e->getMessage())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$columns = [
|
||||
'label',
|
||||
'idUser',
|
||||
'validity',
|
||||
'lastUsage',
|
||||
'options',
|
||||
];
|
||||
|
||||
$column_names = [
|
||||
__('Label'),
|
||||
__('For user'),
|
||||
__('Expiration'),
|
||||
__('Last usage'),
|
||||
[
|
||||
'text' => __('Options'),
|
||||
'class' => 'w20px table_action_buttons',
|
||||
],
|
||||
];
|
||||
|
||||
$user_users = [$config['id_user'] => get_user_fullname($config['id_user'])];
|
||||
if ((bool) users_is_admin() === true) {
|
||||
$user_users = users_get_user_users(
|
||||
$config['id_user'],
|
||||
'AR',
|
||||
true
|
||||
);
|
||||
$user_users[0] = __('Any');
|
||||
}
|
||||
|
||||
$tableId = 'token_table';
|
||||
// Load datatables user interface.
|
||||
ui_print_datatable(
|
||||
[
|
||||
'id' => $tableId,
|
||||
'class' => 'info_table',
|
||||
'style' => 'width: 100%',
|
||||
'columns' => $columns,
|
||||
'column_names' => $column_names,
|
||||
'ajax_url' => 'include/ajax/token',
|
||||
'ajax_data' => ['list_user_tokens' => 1],
|
||||
'extra_html' => $tokenMsg,
|
||||
'no_sortable_columns' => [ -1 ],
|
||||
'order' => [
|
||||
'field' => 'label',
|
||||
'direction' => 'asc',
|
||||
],
|
||||
'search_button_class' => 'sub filter float-right',
|
||||
'form' => [
|
||||
'inputs' => [
|
||||
[
|
||||
'label' => __('Free search'),
|
||||
'type' => 'text',
|
||||
'id' => 'freeSearch',
|
||||
'name' => 'freeSearch',
|
||||
],
|
||||
[
|
||||
'label' => __('User'),
|
||||
'type' => 'select',
|
||||
'fields' => $user_users,
|
||||
'selected' => $config['id_user'],
|
||||
'id' => 'idUser',
|
||||
'name' => 'idUser',
|
||||
],
|
||||
],
|
||||
],
|
||||
'filter_main_class' => 'box-flat white_table_graph fixed_filter_bar',
|
||||
'dom_elements' => 'lftp',
|
||||
]
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
|
||||
echo '<form method="post" action="'.$edit_url.'">';
|
||||
html_print_action_buttons(
|
||||
html_print_submit_button(
|
||||
__('Create Token'),
|
||||
'crt',
|
||||
false,
|
||||
['icon' => 'next'],
|
||||
true
|
||||
),
|
||||
[
|
||||
'type' => 'data_table',
|
||||
'class' => 'fixed_action_buttons',
|
||||
]
|
||||
);
|
||||
echo '</form>';
|
@ -240,73 +240,10 @@ if (is_metaconsole() === true) {
|
||||
user_meta_print_header();
|
||||
$sec = 'advanced';
|
||||
} else {
|
||||
if (check_acl($config['id_user'], 0, 'PM')) {
|
||||
$buttons = [
|
||||
'user' => [
|
||||
'active' => false,
|
||||
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/user_list&tab=user&pure='.$pure.'">'.html_print_image(
|
||||
'images/user.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('User management'),
|
||||
'class' => 'invert_filter main_menu_icon',
|
||||
]
|
||||
).'</a>',
|
||||
],
|
||||
'profile' => [
|
||||
'active' => false,
|
||||
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/profile_list&tab=profile&pure='.$pure.'">'.html_print_image(
|
||||
'images/suitcase@svg.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('Profile management'),
|
||||
'class' => 'invert_filter main_menu_icon',
|
||||
]
|
||||
).'</a>',
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$buttons = [
|
||||
'user' => [
|
||||
'active' => false,
|
||||
'text' => '<a href="index.php?sec=gusuarios&sec2=godmode/users/user_list&tab=user&pure='.$pure.'">'.html_print_image(
|
||||
'images/user.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('User management'),
|
||||
'class' => 'invert_filter main_menu_icon',
|
||||
]
|
||||
).'</a>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$buttons[$tab]['active'] = true;
|
||||
|
||||
// Header.
|
||||
ui_print_standard_header(
|
||||
__('Users management'),
|
||||
'images/user.svg',
|
||||
false,
|
||||
'',
|
||||
false,
|
||||
$buttons,
|
||||
[
|
||||
[
|
||||
'link' => '',
|
||||
'label' => __('Profiles'),
|
||||
],
|
||||
[
|
||||
'link' => '',
|
||||
'label' => __('Manage users'),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
user_print_header($pure, $tab);
|
||||
$sec = 'gusuarios';
|
||||
}
|
||||
|
||||
|
||||
$disable_user = get_parameter('disable_user', false);
|
||||
$delete_user = (bool) get_parameter('user_del', false);
|
||||
|
||||
|
7
pandora_console/images/setup-password.svg
Normal file
7
pandora_console/images/setup-password.svg
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="20px" height="20px" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Icons / 20 / setup-password</title>
|
||||
<g id="Icons-/-20-/-setup-password" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<path d="M13.208468,9.26583823 L19.39347,13.7454161 C20.5245355,14.5646067 19.9687223,16.4156239 18.5916747,16.4156239 L15.9658602,16.4155425 L14.7930093,19.1348551 C14.2313611,20.436557 12.4230217,20.2083185 12.1400384,18.8589672 L12.1195829,18.7405724 L11.0151183,10.6773323 C10.8414908,9.40975022 12.2000464,8.53547418 13.208468,9.26583823 Z M17,0 C18.6568542,0 20,1.34314575 20,3 L20,9 C20,9.81609934 19.6741328,10.5560883 19.1454186,11.0969469 L17.4692534,9.88328821 C17.7850281,9.71518084 18,9.3826951 18,9 L18,3 C18,2.44771525 17.5522847,2 17,2 L3,2 C2.44771525,2 2,2.44771525 2,3 L2,9 C2,9.55228475 2.44771525,10 3,10 L9.02768756,10.0002458 C8.98874158,10.3032607 8.98869844,10.6207909 9.03362053,10.9487486 L9.177,12 L3,12 C1.34314575,12 0,10.6568542 0,9 L0,3 C0,1.34314575 1.34314575,0 3,0 L17,0 Z M6.52839506,4 L6.52839506,5.31948052 L7.67407407,4.91428571 L8,5.93246753 L6.8345679,6.32727273 L7.5654321,7.36623377 L6.74567901,8 L5.99506173,6.95064935 L5.26419753,8 L4.44444444,7.35584416 L5.1654321,6.32727273 L4,5.93246753 L4.31604938,4.91428571 L5.47160494,5.31948052 L5.47160494,4 L6.52839506,4 Z M11.5283951,4 L11.5283951,5.31948052 L12.6740741,4.91428571 L13,5.93246753 L11.8345679,6.32727273 L12.5654321,7.36623377 L11.745679,8 L10.9950617,6.95064935 L10.2641975,8 L9.44444444,7.35584416 L10.1654321,6.32727273 L9,5.93246753 L9.31604938,4.91428571 L10.4716049,5.31948052 L10.4716049,4 L11.5283951,4 Z" id="Path-91" fill="#3F3F3F"></path>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.8 KiB |
164
pandora_console/include/ajax/token.php
Normal file
164
pandora_console/include/ajax/token.php
Normal file
@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* Tokens ajax.
|
||||
*
|
||||
* @category Users
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2024 Pandora FMS
|
||||
* Please see https://pandorafms.com/community/ for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
$list_user_tokens = (bool) get_parameter('list_user_tokens');
|
||||
|
||||
if ($list_user_tokens === true) {
|
||||
global $config;
|
||||
|
||||
// Datatables offset, limit and order.
|
||||
$filter = get_parameter('filter', []);
|
||||
$page = (int) get_parameter('start', 0);
|
||||
$pageSize = (int) get_parameter('length', $config['block_size']);
|
||||
$orderBy = get_datatable_order(true);
|
||||
|
||||
$sortField = ($orderBy['field'] ?? null);
|
||||
$sortDirection = ($orderBy['direction'] ?? null);
|
||||
|
||||
try {
|
||||
ob_start();
|
||||
|
||||
include_once $config['homedir'].'/include/functions_token.php';
|
||||
if (isset($filter['form_token_table_search_bt']) === true) {
|
||||
unset($filter['form_token_table_search_bt']);
|
||||
}
|
||||
|
||||
$return = list_user_tokens(
|
||||
($page / $pageSize),
|
||||
$pageSize,
|
||||
$sortField,
|
||||
strtoupper($sortDirection),
|
||||
$filter
|
||||
);
|
||||
|
||||
if (empty($return['data']) === false) {
|
||||
// Format end of life date.
|
||||
$return['data'] = array_map(
|
||||
function ($item) use ($config) {
|
||||
$itemArray = $item->toArray();
|
||||
|
||||
$sec = 'gusuarios';
|
||||
if (is_metaconsole() === true) {
|
||||
$sec = 'advanced';
|
||||
}
|
||||
|
||||
$edit_url = 'index.php?sec='.$sec;
|
||||
$edit_url .= '&sec2=godmode/users/configure_token&pure=0';
|
||||
$edit_url .= '&id_token='.$itemArray['idToken'];
|
||||
|
||||
$delete_url = 'index.php?sec='.$sec;
|
||||
$delete_url .= '&sec2=godmode/users/token_list';
|
||||
$delete_url .= '&pure=0&delete_token=1';
|
||||
$delete_url .= '&id_token='.$itemArray['idToken'];
|
||||
|
||||
$itemArray['label'] = html_print_anchor(
|
||||
[
|
||||
'href' => $edit_url,
|
||||
'content' => $itemArray['label'],
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
if (empty($itemArray['validity']) === true) {
|
||||
$itemArray['validity'] = __('Never');
|
||||
} else {
|
||||
$itemArray['validity'] = date($config['date_format'], strtotime($itemArray['validity']));
|
||||
}
|
||||
|
||||
if (empty($itemArray['lastUsage']) === true) {
|
||||
$itemArray['lastUsage'] = __('Never');
|
||||
} else {
|
||||
$itemArray['lastUsage'] = human_time_comparation($itemArray['lastUsage']);
|
||||
}
|
||||
|
||||
$itemArray['options'] = '<div class="table_action_buttons float-right">';
|
||||
$itemArray['options'] .= html_print_anchor(
|
||||
[
|
||||
'href' => $edit_url,
|
||||
'content' => html_print_image(
|
||||
'images/edit.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('Show'),
|
||||
'class' => 'main_menu_icon invert_filter',
|
||||
]
|
||||
),
|
||||
],
|
||||
true
|
||||
);
|
||||
$itemArray['options'] .= html_print_anchor(
|
||||
[
|
||||
'href' => $delete_url,
|
||||
'onClick' => 'if (!confirm(\' '.__('Are you sure?').'\')) return false;',
|
||||
'content' => html_print_image(
|
||||
'images/delete.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('Delete'),
|
||||
'class' => 'invert_filter main_menu_icon',
|
||||
]
|
||||
),
|
||||
],
|
||||
true
|
||||
);
|
||||
$itemArray['options'] .= '</div>';
|
||||
|
||||
return $itemArray;
|
||||
},
|
||||
$return['data']
|
||||
);
|
||||
}
|
||||
|
||||
// Datatables format: RecordsTotal && recordsfiltered.
|
||||
echo json_encode(
|
||||
[
|
||||
'data' => $return['data'],
|
||||
'recordsTotal' => $return['paginationData']['totalRegisters'],
|
||||
'recordsFiltered' => $return['paginationData']['totalRegisters'],
|
||||
]
|
||||
);
|
||||
// Capture output.
|
||||
$response = ob_get_clean();
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['error' => $e->getMessage()]);
|
||||
return;
|
||||
}
|
||||
|
||||
// If not valid, show error with issue.
|
||||
json_decode($response);
|
||||
if (json_last_error() == JSON_ERROR_NONE) {
|
||||
// If valid dump.
|
||||
echo $response;
|
||||
} else {
|
||||
echo json_encode(
|
||||
['error' => $response]
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
@ -17,7 +17,9 @@
|
||||
* @subpackage Config
|
||||
*/
|
||||
|
||||
/**
|
||||
use DI\ContainerBuilder;
|
||||
|
||||
/*
|
||||
* Pandora build version and version
|
||||
*/
|
||||
$build_version = 'PC240301';
|
||||
@ -336,3 +338,15 @@ if (isset($config['console_log_enabled']) === true
|
||||
ini_set('log_errors', false);
|
||||
ini_set('error_log', '');
|
||||
}
|
||||
|
||||
global $container;
|
||||
if (empty($container) === true) {
|
||||
include_once $config['homedir'].'/vendor/autoload.php';
|
||||
|
||||
// Solution to load the ContainerBuilder class.
|
||||
$containerBuilder = new ContainerBuilder();
|
||||
$containerBuilder->addDefinitions(__DIR__.'/../api/v1/config/container.php');
|
||||
|
||||
// Create DI container instance.
|
||||
$container = $containerBuilder->build();
|
||||
}
|
||||
|
@ -820,6 +820,7 @@ define('AUDIT_LOG_UMC', 'Warp Manager');
|
||||
define('AUDIT_LOG_NMS_VIOLATION', 'NMS Violation');
|
||||
define('AUDIT_LOG_ENTERPRISE_VIOLATION', 'Enterprise Violation');
|
||||
define('AUDIT_LOG_CRON_TASK', 'Cron task');
|
||||
define('AUDIT_LOG_EVENT', 'Events');
|
||||
|
||||
// MIMEs.
|
||||
define(
|
||||
|
@ -2767,11 +2767,12 @@ function get_os_name($id_os)
|
||||
/**
|
||||
* Get user's dashboards
|
||||
*
|
||||
* @param int user id.
|
||||
* @param integer $id_user User id.
|
||||
* @param integer $id_dashboard Dashboard id.
|
||||
*
|
||||
* @return array Dashboard name of the given user.
|
||||
*/
|
||||
function get_user_dashboards($id_user)
|
||||
function get_user_dashboards($id_user, $id_dashboard=null)
|
||||
{
|
||||
if (users_is_admin($id_user)) {
|
||||
$sql = "SELECT id, name
|
||||
@ -2798,6 +2799,10 @@ function get_user_dashboards($id_user)
|
||||
}
|
||||
}
|
||||
|
||||
if ($id_dashboard !== null) {
|
||||
$sql .= sprintf(' AND id = %d', $id_dashboard);
|
||||
}
|
||||
|
||||
return db_get_all_rows_sql($sql);
|
||||
}
|
||||
|
||||
|
@ -678,6 +678,7 @@ function events_update_status($id_evento, $status, $filter=null)
|
||||
*/
|
||||
function get_filter_date(array $filter)
|
||||
{
|
||||
$sql_filters = [];
|
||||
if (isset($filter['date_from']) === true
|
||||
&& empty($filter['date_from']) === false
|
||||
&& $filter['date_from'] !== '0000-00-00'
|
||||
@ -826,6 +827,13 @@ function events_get_all(
|
||||
|
||||
$sql_filters = get_filter_date($filter);
|
||||
|
||||
if (isset($filter['id_event']) === true && $filter['id_event'] > 0) {
|
||||
$sql_filters[] = sprintf(
|
||||
' AND te.id_evento = %d ',
|
||||
$filter['id_event']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($filter['id_agent']) === true && $filter['id_agent'] > 0) {
|
||||
$sql_filters[] = sprintf(
|
||||
' AND te.id_agente = %d ',
|
||||
@ -1924,7 +1932,7 @@ function events_get_all(
|
||||
&& $sort_field !== 'server_name'
|
||||
&& $sort_field !== 'timestamp'
|
||||
) {
|
||||
$sort_field = explode('.', $sort_field)[1];
|
||||
$sort_field = (explode('.', $sort_field)[1] ?? $sort_field);
|
||||
if ($sort_field === 'user_comment') {
|
||||
$sort_field = 'comments';
|
||||
}
|
||||
|
@ -73,6 +73,10 @@ function io_safe_input($value)
|
||||
{
|
||||
// Stop!! Are you sure to modify this critical code? Because the older
|
||||
// versions are serius headache in many places of Pandora.
|
||||
if (empty($value) === true) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_numeric($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
@ -37,26 +37,27 @@ enterprise_include_once(
|
||||
|
||||
// Date format for nfdump.
|
||||
global $nfdump_date_format;
|
||||
$nfdump_date_format = 'Y/m/d.H:i:s';/**
|
||||
* Generates a Tree with given $tree information.
|
||||
*
|
||||
* Selects all netflow filters (array (id_name => id_name)) or filters filtered
|
||||
* Used also in Cloud Wizard.
|
||||
*
|
||||
* @param string $tree SNMP tree returned by snmp_broser_get_tree.
|
||||
* @param string $id Level ID. Do not set, used for recursion.
|
||||
* @param string $depth Branch depth. Do not set, used for recursion.
|
||||
* @param integer $last Last.
|
||||
* @param array $last_array Last_array.
|
||||
* @param string $sufix Sufix.
|
||||
* @param array $checked Checked.
|
||||
* @param boolean $descriptive_ids Descriptive_ids.
|
||||
* @param string $previous_id Previous_id.
|
||||
*
|
||||
* @return string HTML code with complete tree.
|
||||
*/
|
||||
$nfdump_date_format = 'Y/m/d.H:i:s';
|
||||
|
||||
|
||||
/**
|
||||
* Generates a Tree with given $tree information.
|
||||
*
|
||||
* Selects all netflow filters (array (id_name => id_name)) or filters filtered
|
||||
* Used also in Cloud Wizard.
|
||||
*
|
||||
* @param string $tree SNMP tree returned by snmp_broser_get_tree.
|
||||
* @param string $id Level ID. Do not set, used for recursion.
|
||||
* @param string $depth Branch depth. Do not set, used for recursion.
|
||||
* @param integer $last Last.
|
||||
* @param array $last_array Last_array.
|
||||
* @param string $sufix Sufix.
|
||||
* @param array $checked Checked.
|
||||
* @param boolean $descriptive_ids Descriptive_ids.
|
||||
* @param string $previous_id Previous_id.
|
||||
*
|
||||
* @return string HTML code with complete tree.
|
||||
*/
|
||||
function snmp_browser_get_html_tree(
|
||||
$tree,
|
||||
$id=0,
|
||||
|
157
pandora_console/include/functions_token.php
Normal file
157
pandora_console/include/functions_token.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* Functions Token.
|
||||
*
|
||||
* @category Users
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
*
|
||||
* Pandora FMS - https://pandorafms.com
|
||||
* ==================================================
|
||||
* Copyright (c) 2005-2024 Pandora FMS
|
||||
* Please see https://pandorafms.com/community/ for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Actions\CreateTokenAction;
|
||||
use PandoraFMS\Modules\Authentication\Actions\DeleteTokenAction;
|
||||
use PandoraFMS\Modules\Authentication\Actions\GetTokenAction;
|
||||
use PandoraFMS\Modules\Authentication\Actions\ListTokenAction;
|
||||
use PandoraFMS\Modules\Authentication\Actions\UpdateTokenAction;
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Entities\TokenFilter;
|
||||
|
||||
|
||||
/**
|
||||
* Get token.
|
||||
*
|
||||
* @param integer $idToken Token ID.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_user_token(int $idToken): array
|
||||
{
|
||||
global $container;
|
||||
$token = $container->get(GetTokenAction::class)->__invoke($idToken)->toArray();
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get info tokens for user.
|
||||
*
|
||||
* @param integer $page Page.
|
||||
* @param integer $pageSize Size page.
|
||||
* @param string|null $sortField Sort field.
|
||||
* @param string|null $sortDirection Sort direction.
|
||||
* @param array $filters Filters.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function list_user_tokens(
|
||||
int $page=0,
|
||||
int $pageSize=0,
|
||||
?string $sortField=null,
|
||||
?string $sortDirection=null,
|
||||
array $filters=[]
|
||||
): array {
|
||||
global $config;
|
||||
global $container;
|
||||
|
||||
$tokenFilter = new TokenFilter;
|
||||
$tokenFilter->setPage($page);
|
||||
$tokenFilter->setSizePage($pageSize);
|
||||
$tokenFilter->setSortField($sortField);
|
||||
$tokenFilter->setSortDirection($sortDirection);
|
||||
|
||||
if (empty($filters['freeSearch']) === false) {
|
||||
$tokenFilter->setFreeSearch($filters['freeSearch']);
|
||||
}
|
||||
|
||||
// phpcs:ignore
|
||||
/** @var Token $entityFilter */
|
||||
$entityFilter = $tokenFilter->getEntityFilter();
|
||||
|
||||
if (empty($filters['idUser']) === false) {
|
||||
$entityFilter->setIdUser($filters['idUser']);
|
||||
}
|
||||
|
||||
$result = $container->get(ListTokenAction::class)->__invoke($tokenFilter);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create token.
|
||||
*
|
||||
* @param array $params Params.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function create_user_token(array $params): array
|
||||
{
|
||||
global $container;
|
||||
|
||||
$token = new Token;
|
||||
$token->setIdUser($params['idUser']);
|
||||
$token->setLabel(io_safe_output($params['label']));
|
||||
$token->setValidity((empty($params['validity']) === false) ? io_safe_output($params['validity']) : null);
|
||||
$result = $container->get(CreateTokenAction::class)->__invoke($token)->toArray();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update token.
|
||||
*
|
||||
* @param integer $idToken Token ID.
|
||||
* @param array $params Params.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function update_user_token(int $idToken, array $params): array
|
||||
{
|
||||
global $container;
|
||||
|
||||
$token = $container->get(GetTokenAction::class)->__invoke($idToken);
|
||||
$oldToken = clone $token;
|
||||
|
||||
$token->setIdUser($params['idUser']);
|
||||
$token->setLabel(io_safe_output($params['label']));
|
||||
$token->setValidity((empty($params['validity']) === false) ? io_safe_output($params['validity']) : null);
|
||||
|
||||
$result = $container->get(UpdateTokenAction::class)->__invoke($token, $oldToken)->toArray();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete token.
|
||||
*
|
||||
* @param integer $idToken Token ID.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function delete_user_token(int $idToken): bool
|
||||
{
|
||||
global $container;
|
||||
|
||||
$token = $container->get(GetTokenAction::class)->__invoke($idToken);
|
||||
$container->get(DeleteTokenAction::class)->__invoke($token);
|
||||
$result = true;
|
||||
|
||||
return $result;
|
||||
}
|
@ -1016,3 +1016,113 @@ function checkIPInRange(
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build header user options to manage.
|
||||
*
|
||||
* @param integer $pure Pure.
|
||||
* @param string $tab Tab.
|
||||
* @param string $title Title.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function user_print_header(int $pure=0, string $tab='user', ?string $title=null): void
|
||||
{
|
||||
global $config;
|
||||
|
||||
$url_list_user = 'index.php?sec=gusuarios&sec2=godmode/users/user_list';
|
||||
$url_list_user .= '&tab=user&pure='.$pure;
|
||||
|
||||
$url_list_profile = 'index.php?sec=gusuarios&sec2=godmode/users/profile_list';
|
||||
$url_list_profile .= '&tab=profile&pure='.$pure;
|
||||
|
||||
$url_list_token = 'index.php?sec=gusuarios&sec2=godmode/users/token_list';
|
||||
$url_list_token .= '&tab=token&pure='.$pure;
|
||||
|
||||
if ((bool) check_acl($config['id_user'], 0, 'PM') === true) {
|
||||
$buttons['user'] = [
|
||||
'active' => false,
|
||||
'text' => '<a href="'.$url_list_user.'">'.html_print_image(
|
||||
'images/user.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('User management'),
|
||||
'class' => 'invert_filter main_menu_icon',
|
||||
]
|
||||
).'</a>',
|
||||
];
|
||||
|
||||
$buttons['profile'] = [
|
||||
'active' => false,
|
||||
'text' => '<a href="'.$url_list_profile.'">'.html_print_image(
|
||||
'images/suitcase@svg.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('Profile management'),
|
||||
'class' => 'invert_filter main_menu_user',
|
||||
]
|
||||
).'</a>',
|
||||
];
|
||||
}
|
||||
|
||||
$buttons['token'] = [
|
||||
'active' => false,
|
||||
'text' => '<a href="'.$url_list_token.'">'.html_print_image(
|
||||
'images/setup-password.svg',
|
||||
true,
|
||||
[
|
||||
'title' => __('Token management'),
|
||||
'class' => 'invert_filter main_menu_user',
|
||||
]
|
||||
).'</a>',
|
||||
];
|
||||
|
||||
if (isset($buttons[$tab]) === true) {
|
||||
$buttons[$tab]['active'] = true;
|
||||
}
|
||||
|
||||
switch ($tab) {
|
||||
case 'token':
|
||||
$title = (empty($title) === false) ? $title : __('Token management');
|
||||
$img = 'images/setup-password.svg';
|
||||
$tab_name = 'token_tab';
|
||||
$short_title = __('Token');
|
||||
break;
|
||||
|
||||
case 'profile':
|
||||
$title = (empty($title) === false) ? $title : __('Profile management');
|
||||
$img = 'images/suitcase@svg.svg';
|
||||
$tab_name = 'profile_tab';
|
||||
$short_title = __('Profile');
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
default:
|
||||
$title = (empty($title) === false) ? $title : __('User management');
|
||||
$img = 'images/user.svg';
|
||||
$tab_name = 'user_tab';
|
||||
$short_title = __('User');
|
||||
break;
|
||||
}
|
||||
|
||||
// Header.
|
||||
ui_print_standard_header(
|
||||
$title,
|
||||
$img,
|
||||
false,
|
||||
$tab_name,
|
||||
false,
|
||||
$buttons,
|
||||
[
|
||||
[
|
||||
'link' => '',
|
||||
'label' => $short_title,
|
||||
],
|
||||
[
|
||||
'link' => $url_list_user,
|
||||
'label' => __('Manage users'),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Services\CreateTokenService;
|
||||
use PandoraFMS\Modules\Shared\Services\ValidateAclSystem;
|
||||
|
||||
final class CreateTokenAction
|
||||
{
|
||||
public function __construct(
|
||||
private CreateTokenService $createTokenService,
|
||||
private ValidateAclSystem $acl,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Token $token): Token
|
||||
{
|
||||
$this->acl->validateAclToken($token);
|
||||
return $this->createTokenService->__invoke($token);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Services\DeleteTokenService;
|
||||
use PandoraFMS\Modules\Shared\Services\ValidateAclSystem;
|
||||
|
||||
final class DeleteTokenAction
|
||||
{
|
||||
public function __construct(
|
||||
private DeleteTokenService $deleteTokenService,
|
||||
private ValidateAclSystem $acl,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Token $token): void
|
||||
{
|
||||
$this->acl->validateAclToken($token);
|
||||
$this->deleteTokenService->__invoke($token);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Services\GetTokenService;
|
||||
|
||||
final class GetTokenAction
|
||||
{
|
||||
public function __construct(
|
||||
private GetTokenService $getTokenService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(int $idToken): Token
|
||||
{
|
||||
return $this->getTokenService->__invoke($idToken);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\TokenFilter;
|
||||
use PandoraFMS\Modules\Authentication\Services\CountTokenService;
|
||||
use PandoraFMS\Modules\Authentication\Services\ListTokenService;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Entities\PaginationData;
|
||||
|
||||
final class ListTokenAction
|
||||
{
|
||||
public function __construct(
|
||||
private ListTokenService $listTokenService,
|
||||
private CountTokenService $countTokenService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(TokenFilter $tokenFilter): array
|
||||
{
|
||||
return (new PaginationData(
|
||||
$tokenFilter->getPage(),
|
||||
$tokenFilter->getSizePage(),
|
||||
$this->countTokenService->__invoke($tokenFilter),
|
||||
$this->listTokenService->__invoke($tokenFilter)
|
||||
))->toArray();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Services\UpdateTokenService;
|
||||
use PandoraFMS\Modules\Shared\Services\ValidateAclSystem;
|
||||
|
||||
final class UpdateTokenAction
|
||||
{
|
||||
public function __construct(
|
||||
private UpdateTokenService $updateTokenService,
|
||||
private ValidateAclSystem $acl,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Token $token, Token $oldToken): Token
|
||||
{
|
||||
$this->acl->validateAclToken($token);
|
||||
return $this->updateTokenService->__invoke($token, $oldToken);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Actions\CreateTokenAction;
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
final class CreateTokenController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private CreateTokenAction $createTokenAction
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* tags={"Authentication"},
|
||||
* path="/token",
|
||||
* summary="Creates a new tokens",
|
||||
* @OA\RequestBody(ref="#/components/requestBodies/requestBodyToken"),
|
||||
* @OA\Response(response=200, ref="#/components/responses/ResponseToken"),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
// @var Token $token.
|
||||
$token = $this->fromRequest($request, Token::class);
|
||||
|
||||
$result = $this->createTokenAction->__invoke($token);
|
||||
|
||||
return $this->getResponse($response, $result);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Actions\DeleteTokenAction;
|
||||
use PandoraFMS\Modules\Authentication\Actions\GetTokenAction;
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
final class DeleteTokenController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private DeleteTokenAction $deleteTokenAction,
|
||||
private GetTokenAction $getTokenAction
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Delete(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* tags={"Authentication"},
|
||||
* path="/token/{id}",
|
||||
* summary="Deletes an token object.",
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterIdToken"),
|
||||
* @OA\Response(response=200, ref="#/components/responses/successfullyDeleted"),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
$idToken = $this->getParam($request, 'id');
|
||||
$token = $this->getTokenAction->__invoke($idToken);
|
||||
|
||||
$result = $this->deleteTokenAction->__invoke($token);
|
||||
return $this->getResponse($response, $result);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Actions\GetTokenAction;
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
final class GetTokenController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private GetTokenAction $getTokenAction
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* path="/token/{id}",
|
||||
* tags={"Authentication"},
|
||||
* summary="show tokens",
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterIdToken"),
|
||||
* @OA\Response(response=200, ref="#/components/responses/ResponseToken"),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
$idToken = $this->getParam($request, 'id');
|
||||
|
||||
$result = $this->getTokenAction->__invoke($idToken);
|
||||
return $this->getResponse($response, $result);
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Actions\ListTokenAction;
|
||||
use PandoraFMS\Modules\Authentication\Entities\TokenFilter;
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
final class ListTokenController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private ListTokenAction $listTokenAction
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* tags={"Authentication"},
|
||||
* path="/token/list",
|
||||
* summary="List tokens",
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterPage"),
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterSizePage"),
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterSortField"),
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterSortDirection"),
|
||||
* @OA\RequestBody(ref="#/components/requestBodies/requestBodyTokenFilter"),
|
||||
* @OA\Response(
|
||||
* response="200",
|
||||
* description="List Incidence object",
|
||||
* content={
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(
|
||||
* @OA\Property(
|
||||
* property="paginationData",
|
||||
* type="object",
|
||||
* ref="#/components/schemas/paginationData",
|
||||
* description="Page object",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="data",
|
||||
* type="array",
|
||||
* @OA\Items(
|
||||
* ref="#/components/schemas/Token",
|
||||
* description="Array of Token objects"
|
||||
* )
|
||||
* ),
|
||||
* ),
|
||||
* )
|
||||
* }
|
||||
* ),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
// @var TokenFilter $tokenFilter.
|
||||
$tokenFilter = $this->fromRequest($request, TokenFilter::class);
|
||||
|
||||
$result = $this->listTokenAction->__invoke($tokenFilter);
|
||||
return $this->getResponse($response, $result);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
final class PingController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* path="/ping",
|
||||
* tags={"Authentication"},
|
||||
* summary="ping",
|
||||
* @OA\Response(response=200, ref="#/components/responses/ResponsePing"),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*
|
||||
* @OA\Response(
|
||||
* response="ResponsePing",
|
||||
* description="Ping",
|
||||
* content={
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Property(
|
||||
* property="valid",
|
||||
* type="bool",
|
||||
* nullable=false,
|
||||
* description="Is valid token",
|
||||
* readOnly=true
|
||||
* )
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
return $this->getResponse($response, ['valid' => true]);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Actions\GetTokenAction;
|
||||
use PandoraFMS\Modules\Authentication\Actions\UpdateTokenAction;
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
/**
|
||||
* @OA\Put(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* path="/token/{id}",
|
||||
* tags={"Authentication"},
|
||||
* summary="Updates an token",
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterIdToken"),
|
||||
* @OA\RequestBody(ref="#/components/requestBodies/requestBodyToken"),
|
||||
* @OA\Response(response=200, ref="#/components/responses/ResponseToken"),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*/
|
||||
final class UpdateTokenController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private UpdateTokenAction $updateTokenAction,
|
||||
private GetTokenAction $getTokenAction
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
$idToken = $this->getParam($request, 'id');
|
||||
$token = $this->getTokenAction->__invoke($idToken);
|
||||
|
||||
$oldToken = clone $token;
|
||||
$params = $this->extractParams($request);
|
||||
$token->fromArray($params);
|
||||
|
||||
$result = $this->updateTokenAction->__invoke($token, $oldToken);
|
||||
return $this->getResponse($response, $result);
|
||||
}
|
||||
}
|
@ -0,0 +1,341 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Entities;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Entities\Entity;
|
||||
use PandoraFMS\Modules\Shared\Validators\Validator;
|
||||
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="Token",
|
||||
* type="object",
|
||||
* @OA\Property(
|
||||
* property="idToken",
|
||||
* type="integer",
|
||||
* nullable=false,
|
||||
* description="Id Token",
|
||||
* readOnly=true
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="label",
|
||||
* type="string",
|
||||
* nullable=false,
|
||||
* default=null,
|
||||
* description="label of the token"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="uuid",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="uuid of the token",
|
||||
* readOnly=true
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="idUser",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="id_user of the token"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="validity",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Date until which tocken is valid, if it is void it will never expire",
|
||||
* example="2023-02-21 08:34:16",
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="lastUsage",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="last_usage of the token",
|
||||
* example="2023-02-21 08:34:16",
|
||||
* readOnly=true
|
||||
* )
|
||||
* )
|
||||
*
|
||||
* @OA\Response(
|
||||
* response="ResponseToken",
|
||||
* description="Incidence type object",
|
||||
* content={
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(
|
||||
* type="object",
|
||||
* ref="#/components/schemas/Token",
|
||||
* description="Incidence type object"
|
||||
* ),
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* @OA\Parameter(
|
||||
* parameter="parameterIdToken",
|
||||
* name="id",
|
||||
* in="path",
|
||||
* description="Token id",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="integer",
|
||||
* default=1
|
||||
* ),
|
||||
* )
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* request="requestBodyToken",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(ref="#/components/schemas/Token")
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
final class Token extends Entity
|
||||
{
|
||||
private ?int $idToken = null;
|
||||
private ?string $label = null;
|
||||
private ?string $uuid = null;
|
||||
private ?string $challenge = null;
|
||||
private ?string $idUser = null;
|
||||
private ?string $validity = null;
|
||||
private ?string $lastUsage = null;
|
||||
|
||||
private ?string $token = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function fieldsReadOnly(): array
|
||||
{
|
||||
return [
|
||||
'idToken' => 1,
|
||||
'uuid' => 1,
|
||||
'challenge' => 1,
|
||||
'token' => 1,
|
||||
'lastUsage' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'idToken' => $this->getIdToken(),
|
||||
'label' => $this->getLabel(),
|
||||
'uuid' => $this->getUuid(),
|
||||
'idUser' => $this->getIdUser(),
|
||||
'validity' => $this->getValidity(),
|
||||
'lastUsage' => $this->getLastUsage(),
|
||||
'token' => $this->getToken(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getValidations(): array
|
||||
{
|
||||
return [
|
||||
'idToken' => [
|
||||
Validator::INTEGER,
|
||||
Validator::GREATERTHAN,
|
||||
],
|
||||
'label' => Validator::STRING,
|
||||
'uuid' => Validator::STRING,
|
||||
'challenge' => Validator::STRING,
|
||||
'idUser' => Validator::STRING,
|
||||
'validity' => Validator::DATETIME,
|
||||
'lastUsage' => Validator::DATETIME,
|
||||
];
|
||||
}
|
||||
|
||||
public function validateFields(array $filters): array
|
||||
{
|
||||
return (new Validator())->validate($filters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of idToken.
|
||||
*
|
||||
* @return ?int
|
||||
*/
|
||||
public function getIdToken(): ?int
|
||||
{
|
||||
return $this->idToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of idToken.
|
||||
*
|
||||
* @param ?int $idToken
|
||||
*
|
||||
*/
|
||||
public function setIdToken(?int $idToken): self
|
||||
{
|
||||
$this->idToken = $idToken;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the value of label.
|
||||
*
|
||||
* @return ?string
|
||||
*/
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of label.
|
||||
*
|
||||
* @param ?string $label
|
||||
*
|
||||
*/
|
||||
public function setLabel(?string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of uuid.
|
||||
*
|
||||
* @return ?string
|
||||
*/
|
||||
public function getUuid(): ?string
|
||||
{
|
||||
return $this->uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of uuid.
|
||||
*
|
||||
* @param ?string $uuid
|
||||
*
|
||||
*/
|
||||
public function setUuid(?string $uuid): self
|
||||
{
|
||||
$this->uuid = $uuid;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of challenge.
|
||||
*
|
||||
* @return ?string
|
||||
*/
|
||||
public function getChallenge(): ?string
|
||||
{
|
||||
return $this->challenge;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of challenge.
|
||||
*
|
||||
* @param ?string $challenge
|
||||
*
|
||||
*/
|
||||
public function setChallenge(?string $challenge): self
|
||||
{
|
||||
$this->challenge = $challenge;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of idUser.
|
||||
*
|
||||
* @return ?string
|
||||
*/
|
||||
public function getIdUser(): ?string
|
||||
{
|
||||
return $this->idUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of idUser.
|
||||
*
|
||||
* @param ?string $idUser
|
||||
*
|
||||
*/
|
||||
public function setIdUser(?string $idUser): self
|
||||
{
|
||||
$this->idUser = $idUser;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of validity.
|
||||
*
|
||||
* @return ?string
|
||||
*/
|
||||
public function getValidity(): ?string
|
||||
{
|
||||
return $this->validity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of validity.
|
||||
*
|
||||
* @param ?string $validity
|
||||
*
|
||||
*/
|
||||
public function setValidity(?string $validity): self
|
||||
{
|
||||
$this->validity = $validity;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of lastUsage.
|
||||
*
|
||||
* @return ?string
|
||||
*/
|
||||
public function getLastUsage(): ?string
|
||||
{
|
||||
return $this->lastUsage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of lastUsage.
|
||||
*
|
||||
* @param ?string $lastUsage
|
||||
*
|
||||
*/
|
||||
public function setLastUsage(?string $lastUsage): self
|
||||
{
|
||||
$this->lastUsage = $lastUsage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of token.
|
||||
*
|
||||
* @return ?string
|
||||
*/
|
||||
public function getToken(): ?string
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of token.
|
||||
*
|
||||
* @param ?string $token
|
||||
*
|
||||
*/
|
||||
public function setToken(?string $token): self
|
||||
{
|
||||
$this->token = $token;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Entities;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Builders\Builder;
|
||||
use PandoraFMS\Modules\Shared\Core\DataMapperAbstract;
|
||||
use PandoraFMS\Modules\Shared\Core\MappeableInterface;
|
||||
use PandoraFMS\Modules\Shared\Repositories\Repository;
|
||||
|
||||
final class TokenDataMapper extends DataMapperAbstract
|
||||
{
|
||||
public const TABLE_NAME = 'ttoken';
|
||||
public const ID_TOKEN = 'id';
|
||||
public const LABEL = 'label';
|
||||
public const UUID = 'uuid';
|
||||
public const CHALLENGE = 'challenge';
|
||||
public const ID_USER = 'id_user';
|
||||
public const VALIDITY = 'validity';
|
||||
public const LAST_USAGE = 'last_usage';
|
||||
|
||||
public function __construct(
|
||||
private Repository $repository,
|
||||
private Builder $builder,
|
||||
) {
|
||||
parent::__construct(
|
||||
self::TABLE_NAME,
|
||||
self::ID_TOKEN,
|
||||
);
|
||||
}
|
||||
|
||||
public function getClassName(): string
|
||||
{
|
||||
return Token::class;
|
||||
}
|
||||
|
||||
public function fromDatabase(array $data): Token
|
||||
{
|
||||
return $this->builder->build(new Token(), [
|
||||
'idToken' => $data[self::ID_TOKEN],
|
||||
'label' => $this->repository->safeOutput($data[self::LABEL]),
|
||||
'uuid' => $data[self::UUID],
|
||||
'challenge' => $data[self::CHALLENGE],
|
||||
'idUser' => $data[self::ID_USER],
|
||||
'validity' => $data[self::VALIDITY],
|
||||
'lastUsage' => $data[self::LAST_USAGE],
|
||||
]);
|
||||
}
|
||||
|
||||
public function toDatabase(MappeableInterface $data): array
|
||||
{
|
||||
/** @var Token $data */
|
||||
return [
|
||||
self::ID_TOKEN => $data->getIdToken(),
|
||||
self::LABEL => $this->repository->safeInput($data->getLabel()),
|
||||
self::UUID => $data->getUuid(),
|
||||
self::CHALLENGE => $data->getChallenge(),
|
||||
self::ID_USER => $data->getIdUser(),
|
||||
self::VALIDITY => $data->getValidity(),
|
||||
self::LAST_USAGE => $data->getLastUsage(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Entities;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Core\FilterAbstract;
|
||||
use PandoraFMS\Modules\Shared\Validators\Validator;
|
||||
|
||||
/**
|
||||
* @OA\Schema(
|
||||
* schema="TokenFilter",
|
||||
* type="object",
|
||||
* allOf={
|
||||
* @OA\Schema(ref="#/components/schemas/Token"),
|
||||
* @OA\Schema(
|
||||
* @OA\Property(
|
||||
* property="idToken",
|
||||
* default=null,
|
||||
* readOnly=false
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="freeSearch",
|
||||
* type="string",
|
||||
* nullable=true,
|
||||
* default=null,
|
||||
* description="Find word in name field."
|
||||
* )
|
||||
* )
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* @OA\RequestBody(
|
||||
* request="requestBodyTokenFilter",
|
||||
* required=true,
|
||||
* @OA\MediaType(
|
||||
* mediaType="application/json",
|
||||
* @OA\Schema(ref="#/components/schemas/TokenFilter")
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
final class TokenFilter extends FilterAbstract
|
||||
{
|
||||
private ?string $freeSearch = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setDefaultFieldOrder(TokenDataMapper::LABEL);
|
||||
$this->setDefaultDirectionOrder($this::DESC);
|
||||
$this->setEntityFilter(new Token());
|
||||
}
|
||||
|
||||
public function fieldsTranslate(): array
|
||||
{
|
||||
return [
|
||||
'idToken' => TokenDataMapper::ID_TOKEN,
|
||||
'label' => TokenDataMapper::LABEL,
|
||||
'validity' => TokenDataMapper::VALIDITY,
|
||||
'lastUsage' => TokenDataMapper::LAST_USAGE,
|
||||
];
|
||||
}
|
||||
|
||||
public function fieldsReadOnly(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
return [
|
||||
'freeSearch' => $this->getFreeSearch(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getValidations(): array
|
||||
{
|
||||
$validations = [];
|
||||
if ($this->getEntityFilter() !== null) {
|
||||
$validations = $this->getEntityFilter()->getValidations();
|
||||
}
|
||||
|
||||
return $validations;
|
||||
}
|
||||
|
||||
public function validateFields(array $filters): array
|
||||
{
|
||||
return (new Validator())->validate($filters);
|
||||
}
|
||||
|
||||
public function getFreeSearch(): ?string
|
||||
{
|
||||
return $this->freeSearch;
|
||||
}
|
||||
|
||||
public function setFreeSearch(?string $freeSearch): self
|
||||
{
|
||||
$this->freeSearch = $freeSearch;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFieldsFreeSearch(): ?array
|
||||
{
|
||||
return [TokenDataMapper::TABLE_NAME.'.'.TokenDataMapper::LABEL];
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Repositories;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Entities\TokenFilter;
|
||||
|
||||
interface TokenRepository
|
||||
{
|
||||
/**
|
||||
* @return Token[],
|
||||
*/
|
||||
public function list(TokenFilter $tokenFilter): array;
|
||||
|
||||
public function count(TokenFilter $tokenFilter): int;
|
||||
|
||||
public function getOne(TokenFilter $tokenFilter): Token;
|
||||
|
||||
public function create(Token $token): Token;
|
||||
|
||||
public function update(Token $token): Token;
|
||||
|
||||
public function delete(int $id): void;
|
||||
|
||||
public function getExistToken(string $label): Token;
|
||||
}
|
@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Repositories;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use PandoraFMS\Modules\Shared\Core\DataMapperAbstract;
|
||||
use PandoraFMS\Modules\Shared\Core\FilterAbstract;
|
||||
use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum;
|
||||
use PandoraFMS\Modules\Shared\Exceptions\NotFoundException;
|
||||
use PandoraFMS\Modules\Shared\Repositories\RepositoryMySQL;
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Entities\TokenDataMapper;
|
||||
use PandoraFMS\Modules\Authentication\Entities\TokenFilter;
|
||||
use PandoraFMS\Modules\Shared\Services\Config;
|
||||
|
||||
final class TokenRepositoryMySQL extends RepositoryMySQL implements TokenRepository
|
||||
{
|
||||
public function __construct(
|
||||
private TokenDataMapper $tokenDataMapper,
|
||||
private Config $config
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Token[],
|
||||
*/
|
||||
public function list(TokenFilter $tokenFilter): array
|
||||
{
|
||||
try {
|
||||
$sql = $this->getAuthenticationQuery($tokenFilter, $this->tokenDataMapper);
|
||||
$list = $this->dbGetAllRowsSql($sql);
|
||||
} catch (\Throwable $th) {
|
||||
// Capture errors mysql.
|
||||
throw new InvalidArgumentException(
|
||||
strip_tags($th->getMessage()),
|
||||
HttpCodesEnum::INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
if (is_array($list) === false) {
|
||||
throw new NotFoundException(__('%s not found', $this->tokenDataMapper->getStringNameClass()));
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($list as $fields) {
|
||||
$result[] = $this->tokenDataMapper->fromDatabase($fields);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function count(TokenFilter $tokenFilter): int
|
||||
{
|
||||
$sql = $this->getAuthenticationQuery($tokenFilter, $this->tokenDataMapper, true);
|
||||
try {
|
||||
$count = $this->dbGetValueSql($sql);
|
||||
} catch (\Throwable $th) {
|
||||
// Capture errors mysql.
|
||||
throw new InvalidArgumentException(
|
||||
strip_tags($th->getMessage()),
|
||||
HttpCodesEnum::INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
return (int) $count;
|
||||
}
|
||||
|
||||
public function getOne(TokenFilter $tokenFilter): Token
|
||||
{
|
||||
try {
|
||||
$sql = $this->getAuthenticationQuery($tokenFilter, $this->tokenDataMapper);
|
||||
$result = $this->dbGetRowSql($sql);
|
||||
} catch (\Throwable $th) {
|
||||
// Capture errors mysql.
|
||||
throw new InvalidArgumentException(
|
||||
strip_tags($th->getMessage()),
|
||||
HttpCodesEnum::INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($result) === true) {
|
||||
throw new NotFoundException(__('%s not found', $this->tokenDataMapper->getStringNameClass()));
|
||||
}
|
||||
|
||||
return $this->tokenDataMapper->fromDatabase($result);
|
||||
}
|
||||
|
||||
public function getExistToken(string $label): Token
|
||||
{
|
||||
try {
|
||||
$sql = sprintf('SELECT * FROM `ttoken` WHERE `label` = "%s"', $label);
|
||||
$result = $this->dbGetRowSql($sql);
|
||||
} catch (\Throwable $th) {
|
||||
// Capture errors mysql.
|
||||
throw new InvalidArgumentException(
|
||||
strip_tags($th->getMessage()),
|
||||
HttpCodesEnum::INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($result) === true) {
|
||||
throw new NotFoundException(__('%s not found', $this->tokenDataMapper->getStringNameClass()));
|
||||
}
|
||||
|
||||
return $this->tokenDataMapper->fromDatabase($result);
|
||||
}
|
||||
|
||||
public function create(Token $token): Token
|
||||
{
|
||||
$idToken = $this->__create($token, $this->tokenDataMapper);
|
||||
return $token->setIdToken($idToken);
|
||||
}
|
||||
|
||||
public function update(Token $token): Token
|
||||
{
|
||||
return $this->__update(
|
||||
$token,
|
||||
$this->tokenDataMapper,
|
||||
$token->getIdToken()
|
||||
);
|
||||
}
|
||||
|
||||
public function delete(int $id): void
|
||||
{
|
||||
$this->__delete($id, $this->tokenDataMapper);
|
||||
}
|
||||
|
||||
private function getAuthenticationQuery(
|
||||
FilterAbstract $filter,
|
||||
DataMapperAbstract $mapper,
|
||||
bool $count = false
|
||||
): string {
|
||||
$pagination = '';
|
||||
$orderBy = '';
|
||||
$fields = 'COUNT(DISTINCT ttoken.id) as count';
|
||||
$filters = $this->buildQueryFilters($filter, $mapper);
|
||||
|
||||
// Check ACL for user list.
|
||||
if (\users_is_admin() === false) {
|
||||
// No admin.
|
||||
$filters .= sprintf(
|
||||
' AND ttoken.id_user = "%s"',
|
||||
$this->config->get('id_user')
|
||||
);
|
||||
}
|
||||
|
||||
if ($count === false) {
|
||||
$pagination = $this->buildQueryPagination($filter);
|
||||
$orderBy = $this->buildQueryOrderBy($filter);
|
||||
if (empty($filter->getFields()) === true) {
|
||||
$fields = 'DISTINCT ttoken.*';
|
||||
} else {
|
||||
$buildFields = '';
|
||||
foreach ($filter->getFields() as $field) {
|
||||
if (empty($buildFields) === false) {
|
||||
$buildFields .= ' , ';
|
||||
}
|
||||
|
||||
$buildFields .= $field;
|
||||
}
|
||||
|
||||
$fields = $buildFields;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT %s
|
||||
FROM ttoken
|
||||
INNER JOIN tusuario
|
||||
ON tusuario.id_user = ttoken.id_user
|
||||
WHERE %s
|
||||
%s
|
||||
%s',
|
||||
$fields,
|
||||
$filters,
|
||||
$orderBy,
|
||||
$pagination
|
||||
);
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\TokenFilter;
|
||||
use PandoraFMS\Modules\Authentication\Repositories\TokenRepository;
|
||||
|
||||
final class CountTokenService
|
||||
{
|
||||
public function __construct(
|
||||
private TokenRepository $tokenRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(TokenFilter $tokenFilter): int
|
||||
{
|
||||
return $this->tokenRepository->count($tokenFilter);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Repositories\TokenRepository;
|
||||
use PandoraFMS\Modules\Authentication\Validations\TokenValidation;
|
||||
use PandoraFMS\Modules\Shared\Services\Audit;
|
||||
|
||||
final class CreateTokenService
|
||||
{
|
||||
public function __construct(
|
||||
private Audit $audit,
|
||||
private TokenRepository $tokenRepository,
|
||||
private TokenValidation $tokenValidation,
|
||||
private GenerateUserTokenService $generateUserTokenService,
|
||||
private GenerateUserUUIDService $generateUserUUIDService,
|
||||
private PrepareUserTokenService $prepareUserTokenService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Token $token): Token
|
||||
{
|
||||
$this->tokenValidation->__invoke($token);
|
||||
|
||||
$stringToken = $this->generateUserTokenService->__invoke();
|
||||
$userUUID = $this->generateUserUUIDService->__invoke();
|
||||
$hashedToken = $this->prepareUserTokenService->__invoke($stringToken);
|
||||
|
||||
$token->setUuid($userUUID);
|
||||
$token->setChallenge($hashedToken);
|
||||
$token->setToken($userUUID.'-'.$stringToken);
|
||||
$token = $this->tokenRepository->create($token);
|
||||
|
||||
$this->audit->write(
|
||||
AUDIT_LOG_USER_MANAGEMENT,
|
||||
'Create token '.$token->getLabel(),
|
||||
json_encode($token->toArray())
|
||||
);
|
||||
|
||||
return $token;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Repositories\TokenRepository;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Services\Audit;
|
||||
|
||||
final class DeleteTokenService
|
||||
{
|
||||
public function __construct(
|
||||
private Audit $audit,
|
||||
private TokenRepository $tokenRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Token $token): void
|
||||
{
|
||||
$idToken = $token->getIdToken();
|
||||
|
||||
$this->tokenRepository->delete($idToken);
|
||||
|
||||
$this->audit->write(
|
||||
AUDIT_LOG_USER_MANAGEMENT,
|
||||
'Delete token '.$token->getLabel(),
|
||||
json_encode($token->toArray())
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Entities\TokenFilter;
|
||||
use PandoraFMS\Modules\Authentication\Repositories\TokenRepository;
|
||||
use PandoraFMS\Modules\Shared\Exceptions\NotFoundException;
|
||||
|
||||
final class ExistLabelTokenService
|
||||
{
|
||||
public function __construct(
|
||||
private TokenRepository $tokenRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(string $label): bool
|
||||
{
|
||||
$tokenFilter = new TokenFilter();
|
||||
/** @var Token $entityFilter */
|
||||
$entityFilter = $tokenFilter->getEntityFilter();
|
||||
$entityFilter->setLabel($label);
|
||||
|
||||
try {
|
||||
$this->tokenRepository->getOne($tokenFilter);
|
||||
return true;
|
||||
} catch (NotFoundException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
final class GenerateUserTokenService
|
||||
{
|
||||
public function __construct(
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(): string
|
||||
{
|
||||
$base = preg_replace(
|
||||
'/[^a-zA-Z0-9]/', '', base64_encode(random_bytes(100)),
|
||||
);
|
||||
|
||||
$token = substr($base, 0, 8);
|
||||
$token .= '-'.substr($base, 8, 24);
|
||||
|
||||
return $token;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
final class GenerateUserUUIDService
|
||||
{
|
||||
public function __construct(
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(): string
|
||||
{
|
||||
return Uuid::uuid4()->toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Entities\TokenFilter;
|
||||
use PandoraFMS\Modules\Authentication\Repositories\TokenRepository;
|
||||
|
||||
final class GetTokenService
|
||||
{
|
||||
public function __construct(
|
||||
private TokenRepository $tokenRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(int $idToken): Token
|
||||
{
|
||||
$tokenFilter = new TokenFilter();
|
||||
/** @var Token $entityFilter */
|
||||
$entityFilter = $tokenFilter->getEntityFilter();
|
||||
$entityFilter->setIdToken($idToken);
|
||||
|
||||
return $this->tokenRepository->getOne($tokenFilter);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Entities\TokenFilter;
|
||||
use PandoraFMS\Modules\Authentication\Repositories\TokenRepository;
|
||||
|
||||
final class GetUserTokenService
|
||||
{
|
||||
public function __construct(
|
||||
private TokenRepository $tokenRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(string $uuid): Token
|
||||
{
|
||||
$tokenFilter = new TokenFilter();
|
||||
/** @var Token $entityFilter */
|
||||
$entityFilter = $tokenFilter->getEntityFilter();
|
||||
$entityFilter->setUuid($uuid);
|
||||
|
||||
return $this->tokenRepository->getOne($tokenFilter);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\TokenFilter;
|
||||
use PandoraFMS\Modules\Authentication\Repositories\TokenRepository;
|
||||
|
||||
final class ListTokenService
|
||||
{
|
||||
public function __construct(
|
||||
private TokenRepository $tokenRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(TokenFilter $tokenFilter): array
|
||||
{
|
||||
return $this->tokenRepository->list($tokenFilter);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
final class PrepareUserTokenService
|
||||
{
|
||||
public function __construct(
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(string $plainToken): string
|
||||
{
|
||||
return password_hash($plainToken, PASSWORD_DEFAULT);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Repositories\TokenRepository;
|
||||
use PandoraFMS\Modules\Authentication\Validations\TokenValidation;
|
||||
use PandoraFMS\Modules\Shared\Services\Audit;
|
||||
|
||||
final class UpdateTokenService
|
||||
{
|
||||
public function __construct(
|
||||
private Audit $audit,
|
||||
private TokenRepository $tokenRepository,
|
||||
private TokenValidation $tokenValidation
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Token $token, Token $oldToken): Token
|
||||
{
|
||||
$this->tokenValidation->__invoke($token, $oldToken);
|
||||
|
||||
$token = $this->tokenRepository->update($token);
|
||||
|
||||
$this->audit->write(
|
||||
AUDIT_LOG_USER_MANAGEMENT,
|
||||
'Update token '.$token->getLabel(),
|
||||
json_encode($token->toArray())
|
||||
);
|
||||
|
||||
return $token;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Services\Config;
|
||||
|
||||
final class ValidateServerIdentifierTokenService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Config $config,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(string $token): bool {
|
||||
$serverUniqueIdentifier = $this->config->get('server_unique_identifier');
|
||||
$apiPassword = $this->config->get('api_password');
|
||||
|
||||
$tokenUniqueServerIdentifier = md5($serverUniqueIdentifier).md5($apiPassword);
|
||||
return ($tokenUniqueServerIdentifier === $token);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Services;
|
||||
|
||||
final class ValidateUserTokenService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly GetUserTokenService $getUserTokenService,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
string $uuid,
|
||||
string $strToken,
|
||||
): bool {
|
||||
$token = $this->getUserTokenService->__invoke($uuid);
|
||||
$validity = $token?->getValidity();
|
||||
$challenge = $token?->getChallenge();
|
||||
|
||||
if (empty($validity) === false) {
|
||||
if (strtotime($validity) < time()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return password_verify(
|
||||
$strToken,
|
||||
$challenge
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Authentication\Validations;
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Entities\Token;
|
||||
use PandoraFMS\Modules\Authentication\Services\ExistLabelTokenService;
|
||||
use PandoraFMS\Modules\Shared\Exceptions\BadRequestException;
|
||||
use PandoraFMS\Modules\Shared\Services\Config;
|
||||
use PandoraFMS\Modules\Shared\Services\Timestamp;
|
||||
use PandoraFMS\Modules\Users\Services\GetUserService;
|
||||
|
||||
final class TokenValidation
|
||||
{
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
private Timestamp $timestamp,
|
||||
private GetUserService $getUserService,
|
||||
private ExistLabelTokenService $existLabelTokenService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Token $token, ?Token $oldToken = null): void
|
||||
{
|
||||
if (!$token->getLabel()) {
|
||||
throw new BadRequestException(__('Label is missing'));
|
||||
}
|
||||
|
||||
if ($oldToken === null || $oldToken->getLabel() !== $token->getLabel()) {
|
||||
if ($this->existLabelTokenService->__invoke($token->getLabel()) === true) {
|
||||
throw new BadRequestException(
|
||||
__('Label %s is already exists', $token->getLabel())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_user_admin($this->config->get('id_user')) === false
|
||||
|| empty($token->getIdUser()) === true
|
||||
) {
|
||||
$token->setIdUser($this->config->get('id_user'));
|
||||
} else {
|
||||
$this->validateUser($token->getIdUser());
|
||||
}
|
||||
}
|
||||
|
||||
protected function getCurrentTimestamp(): string
|
||||
{
|
||||
return $this->timestamp->getMysqlCurrentTimestamp(0);
|
||||
}
|
||||
|
||||
private function validateUser(string $idUser): void
|
||||
{
|
||||
$this->getUserService->__invoke($idUser);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use PandoraFMS\Modules\Authentication\Controllers\CreateTokenController;
|
||||
use PandoraFMS\Modules\Authentication\Controllers\DeleteTokenController;
|
||||
use PandoraFMS\Modules\Authentication\Controllers\GetTokenController;
|
||||
use PandoraFMS\Modules\Authentication\Controllers\ListTokenController;
|
||||
use PandoraFMS\Modules\Authentication\Controllers\PingController;
|
||||
use PandoraFMS\Modules\Authentication\Controllers\UpdateTokenController;
|
||||
use Slim\App;
|
||||
|
||||
return function (App $app) {
|
||||
$app->map(['GET', 'POST'], '/token/list', ListTokenController::class);
|
||||
$app->get('/token/{id}', GetTokenController::class);
|
||||
$app->post('/token', CreateTokenController::class);
|
||||
$app->put('/token/{id}', UpdateTokenController::class);
|
||||
$app->delete('/token/{id}', DeleteTokenController::class);
|
||||
$app->get('/ping', PingController::class);
|
||||
};
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Services\CreateEventService;
|
||||
|
||||
final class CreateEventAction
|
||||
{
|
||||
public function __construct(
|
||||
private CreateEventService $createEventService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Event $event): Event
|
||||
{
|
||||
return $this->createEventService->__invoke($event);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Services\DeleteEventService;
|
||||
|
||||
final class DeleteEventAction
|
||||
{
|
||||
public function __construct(
|
||||
private DeleteEventService $deleteEventService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Event $event): void
|
||||
{
|
||||
$this->deleteEventService->__invoke($event);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Services\GetEventService;
|
||||
|
||||
final class GetEventAction
|
||||
{
|
||||
public function __construct(
|
||||
private GetEventService $getEventService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(int $idEvent): Event
|
||||
{
|
||||
return $this->getEventService->__invoke($idEvent);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Filters\Entities\EventFilter;
|
||||
use PandoraFMS\Modules\Events\Services\CountEventService;
|
||||
use PandoraFMS\Modules\Events\Services\ListEventService;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Entities\PaginationData;
|
||||
|
||||
final class ListEventAction
|
||||
{
|
||||
public function __construct(
|
||||
private ListEventService $listEventService,
|
||||
private CountEventService $countEventService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(EventFilter $eventFilter): array
|
||||
{
|
||||
return (new PaginationData(
|
||||
$eventFilter->getPage(),
|
||||
$eventFilter->getSizePage(),
|
||||
$this->countEventService->__invoke($eventFilter),
|
||||
$this->listEventService->__invoke($eventFilter)
|
||||
))->toArray();
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Entities\Event;
|
||||
use PandoraFMS\Modules\Events\Services\UpdateEventService;
|
||||
|
||||
final class UpdateEventAction
|
||||
{
|
||||
public function __construct(
|
||||
private UpdateEventService $updateEventService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Event $event, Event $oldEvent): Event
|
||||
{
|
||||
return $this->updateEventService->__invoke($event, $oldEvent);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Comments\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Comments\Entities\EventComment;
|
||||
use PandoraFMS\Modules\Events\Comments\Services\CreateEventCommentService;
|
||||
|
||||
final class CreateEventCommentAction
|
||||
{
|
||||
public function __construct(
|
||||
private CreateEventCommentService $createEventCommentService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(EventComment $eventComment): EventComment
|
||||
{
|
||||
return $this->createEventCommentService->__invoke($eventComment);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Comments\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Comments\Entities\EventComment;
|
||||
use PandoraFMS\Modules\Events\Comments\Services\DeleteEventCommentService;
|
||||
|
||||
final class DeleteEventCommentAction
|
||||
{
|
||||
public function __construct(
|
||||
private DeleteEventCommentService $deleteEventCommentService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(EventComment $eventComment): void
|
||||
{
|
||||
$this->deleteEventCommentService->__invoke($eventComment);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Comments\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Comments\Entities\EventComment;
|
||||
use PandoraFMS\Modules\Events\Comments\Services\GetEventCommentService;
|
||||
|
||||
final class GetEventCommentAction
|
||||
{
|
||||
public function __construct(
|
||||
private GetEventCommentService $getEventCommentService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(int $idTypeField, int $idComment): EventComment
|
||||
{
|
||||
return $this->getEventCommentService->__invoke($idTypeField, $idComment);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Comments\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Comments\Entities\EventCommentFilter;
|
||||
use PandoraFMS\Modules\Events\Comments\Services\CountEventCommentService;
|
||||
use PandoraFMS\Modules\Events\Comments\Services\ListEventCommentService;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Entities\PaginationData;
|
||||
|
||||
final class ListEventCommentAction
|
||||
{
|
||||
public function __construct(
|
||||
private ListEventCommentService $listEventCommentService,
|
||||
private CountEventCommentService $countEventCommentService
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
public function __invoke(EventCommentFilter $eventCommentFilter): array
|
||||
{
|
||||
return (new PaginationData(
|
||||
$eventCommentFilter->getPage(),
|
||||
$eventCommentFilter->getSizePage(),
|
||||
$this->countEventCommentService->__invoke($eventCommentFilter),
|
||||
$this->listEventCommentService->__invoke($eventCommentFilter)
|
||||
))->toArray();
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Comments\Actions;
|
||||
|
||||
use PandoraFMS\Modules\Events\Comments\Entities\EventComment;
|
||||
use PandoraFMS\Modules\Events\Comments\Services\UpdateEventCommentService;
|
||||
|
||||
final class UpdateEventCommentAction
|
||||
{
|
||||
public function __construct(
|
||||
private UpdateEventCommentService $updateEventCommentService
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(EventComment $eventComment, EventComment $oldEventComment): EventComment
|
||||
{
|
||||
return $this->updateEventCommentService->__invoke($eventComment, $oldEventComment);
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace PandoraFMS\Modules\Events\Comments\Controllers;
|
||||
|
||||
use PandoraFMS\Modules\Events\Actions\GetEventAction;
|
||||
use PandoraFMS\Modules\Events\Comments\Actions\CreateEventCommentAction;
|
||||
use PandoraFMS\Modules\Events\Comments\Entities\EventComment;
|
||||
|
||||
use PandoraFMS\Modules\Shared\Controllers\Controller;
|
||||
use PandoraFMS\Modules\Shared\Services\ValidateAclSystem;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
final class CreateEventCommentController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private CreateEventCommentAction $createEventCommentAction,
|
||||
private ValidateAclSystem $acl,
|
||||
private GetEventAction $getEventAction
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* security={{ "bearerAuth": {}}},
|
||||
* tags={"Events"},
|
||||
* path="/event/{idEvent}/comment",
|
||||
* summary="Creates a new field into events comments",
|
||||
* @OA\Parameter(ref="#/components/parameters/parameterIdEvent"),
|
||||
* @OA\RequestBody(ref="#/components/requestBodies/requestBodyEventComment"),
|
||||
* @OA\Response(response=200, ref="#/components/responses/ResponseEventComment"),
|
||||
* @OA\Response(response=400, ref="#/components/responses/BadRequest"),
|
||||
* @OA\Response(response=401, ref="#/components/responses/Unauthorized"),
|
||||
* @OA\Response(response=403, ref="#/components/responses/Forbidden"),
|
||||
* @OA\Response(response=404, ref="#/components/responses/NotFound"),
|
||||
* @OA\Response(response=500, ref="#/components/responses/InternalServerError")
|
||||
* )
|
||||
*/
|
||||
public function __invoke(Request $request, Response $response): Response
|
||||
{
|
||||
$idEvent = $this->getParam($request, 'idEvent');
|
||||
$event = $this->getEventAction->__invoke($idEvent);
|
||||
|
||||
$this->acl->validateUserGroups(
|
||||
$event->getIdGroup(),
|
||||
'EW',
|
||||
' tried to write event'
|
||||
);
|
||||
|
||||
// @var EventComment $eventComment.
|
||||
$eventComment = $this->fromRequest($request, EventComment::class);
|
||||
$eventComment->setIdEvent($idEvent);
|
||||
|
||||
$result = $this->createEventCommentAction->__invoke($eventComment);
|
||||
|
||||
return $this->getResponse($response, $result);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user