mirror of
https://github.com/ellite/Wallos.git
synced 2026-05-03 18:40:41 -05:00
feat: add at a glance dashboard
fix: accept both api_key and apiKey as parameter on the api feat: allow to disable password login when oidc is enabled feat: add get_oidc_settings endpoint to the api feat: refactor css colors feat: ai recommendations with chatgpt, gemini or ollama feat: display ai recommendations on the dashboard
This commit is contained in:
@@ -40,7 +40,9 @@ header('Content-Type: application/json; charset=UTF-8');
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST" || $_SERVER["REQUEST_METHOD"] === "GET") {
|
||||
// if the parameters are not set, return an error
|
||||
|
||||
if (!isset($_REQUEST['api_key'])) {
|
||||
$apiKey = $_REQUEST['api_key'] ?? $_REQUEST['apiKey'] ?? null;
|
||||
|
||||
if (!$apiKey) {
|
||||
$response = [
|
||||
"success" => false,
|
||||
"title" => "Missing parameters"
|
||||
@@ -49,7 +51,6 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" || $_SERVER["REQUEST_METHOD"] === "GET
|
||||
exit;
|
||||
}
|
||||
|
||||
$apiKey = $_REQUEST['api_key'];
|
||||
|
||||
// Get user from API key
|
||||
$sql = "SELECT * FROM user WHERE api_key = :apiKey";
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/*
|
||||
This API Endpoint accepts both POST and GET requests.
|
||||
It receives the following parameters:
|
||||
- api_key: the API key of the user.
|
||||
|
||||
It returns a JSON object with the following properties:
|
||||
- success: whether the request was successful (boolean).
|
||||
- title: the title of the response (string).
|
||||
- oidc_settings: an object containing the OIDC settings.
|
||||
- notes: warning messages or additional information (array).
|
||||
|
||||
Example response:
|
||||
{
|
||||
"success": true,
|
||||
"title": "oidc_settings",
|
||||
"oidc_settings": {
|
||||
"name": "Authentik",
|
||||
"client_id": "CJMLcyyS94cUMXkitNZuokayArnn23TXxpeUv48E",
|
||||
"client_secret": "SzfQBIibfN0gEAgCORrKnGnrYe9yqASWAYUuu1byelVosCHlnoqAdWlMDppblyuByb38Zw78AAlgMmdK6SWpGjOU4IiqaoltkAEh52trcqCB8briP1TqqXZdar4xfhVw",
|
||||
"authorization_url": "https://auth.bellamylab.com/application/o/authorize/",
|
||||
"token_url": "https://auth.bellamylab.com/application/o/token/",
|
||||
"user_info_url": "https://auth.bellamylab.com/application/o/userinfo/",
|
||||
"redirect_url": "http://localhost:80/wallos",
|
||||
"logout_url": "https://auth.bellamylab.com/application/o/wallos/end-session/",
|
||||
"user_identifier_field": "sub",
|
||||
"scopes": "openid email profile",
|
||||
"auth_style": "auto",
|
||||
"created_at": "2025-07-20 20:31:50",
|
||||
"updated_at": "2025-07-20 20:31:50",
|
||||
"auto_create_user": 0,
|
||||
"password_login_disabled": 0
|
||||
},
|
||||
"notes": []
|
||||
}
|
||||
*/
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
|
||||
header('Content-Type: application/json; charset=UTF-8');
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST" || $_SERVER["REQUEST_METHOD"] === "GET") {
|
||||
// if the parameters are not set, return an error
|
||||
|
||||
$apiKey = $_REQUEST['api_key'] ?? $_REQUEST['apiKey'] ?? null;
|
||||
|
||||
if (!$apiKey) {
|
||||
$response = [
|
||||
"success" => false,
|
||||
"title" => "Missing parameters"
|
||||
];
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
// Get user from API key
|
||||
$sql = "SELECT * FROM user WHERE api_key = :apiKey";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindValue(':apiKey', $apiKey);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
// If the user is not found, return an error
|
||||
if (!$user) {
|
||||
$response = [
|
||||
"success" => false,
|
||||
"title" => "Invalid API key"
|
||||
];
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$userId = $user['id'];
|
||||
|
||||
if ($userId !== 1) {
|
||||
$response = [
|
||||
"success" => false,
|
||||
"title" => "Invalid user"
|
||||
];
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM 'oauth_settings' WHERE id = 1";
|
||||
$stmt = $db->prepare($sql);
|
||||
$result = $stmt->execute();
|
||||
$oidc_settings = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($oidc_settings) {
|
||||
unset($oidc_settings['id']);
|
||||
}
|
||||
|
||||
$response = [
|
||||
"success" => true,
|
||||
"title" => "oidc_settings",
|
||||
"oidc_settings" => $oidc_settings,
|
||||
"notes" => []
|
||||
];
|
||||
|
||||
echo json_encode($response);
|
||||
|
||||
$db->close();
|
||||
|
||||
} else {
|
||||
$response = [
|
||||
"success" => false,
|
||||
"title" => "Invalid request method"
|
||||
];
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/*
|
||||
This API Endpoint accepts POST requests only.
|
||||
It receives the following parameters:
|
||||
- api_key: the API key of the user.
|
||||
- disable: '1' to disable password login, '0' to enable it.
|
||||
|
||||
It returns a JSON object with the following properties:
|
||||
- success: whether the request was successful (boolean).
|
||||
- title: the title of the response (string).
|
||||
- message: detailed information or error message (string).
|
||||
|
||||
Example response:
|
||||
{
|
||||
"success": true,
|
||||
"title": "Updated",
|
||||
"message": "Password login has been disabled."
|
||||
}
|
||||
*/
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
|
||||
header('Content-Type: application/json; charset=UTF-8');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'title' => 'Invalid request method',
|
||||
'message' => 'Only POST requests are allowed.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$apiKey = $_POST['api_key'] ?? null;
|
||||
|
||||
// Authenticate user first
|
||||
if (!$apiKey) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'title' => 'Missing API key',
|
||||
'message' => 'API key is required.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM user WHERE api_key = :apiKey";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindValue(':apiKey', $apiKey);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if (!$user || $user['id'] !== 1) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'title' => 'Unauthorized',
|
||||
'message' => 'Invalid API key or insufficient privileges.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Now check 'disable' parameter only after authentication
|
||||
$disable = $_POST['disable'] ?? null;
|
||||
if (!isset($disable)) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'title' => 'Missing parameter',
|
||||
'message' => 'Parameter "disable" is required.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!in_array($disable, ['0', '1'], true)) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'title' => 'Invalid parameter',
|
||||
'message' => 'Parameter "disable" must be "0" or "1".'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Update the password_login_disabled setting
|
||||
$updateSql = "UPDATE oauth_settings SET password_login_disabled = :disable WHERE id = 1";
|
||||
$updateStmt = $db->prepare($updateSql);
|
||||
$updateStmt->bindValue(':disable', intval($disable), SQLITE3_INTEGER);
|
||||
$updateResult = $updateStmt->execute();
|
||||
|
||||
if ($updateResult) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'title' => 'Updated',
|
||||
'message' => "Password login has been " . ($disable === '1' ? "disabled" : "enabled") . "."
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'title' => 'Database error',
|
||||
'message' => 'Failed to update the setting.'
|
||||
]);
|
||||
}
|
||||
|
||||
$db->close();
|
||||
Reference in New Issue
Block a user