49 lines
2.8 KiB
PHP
49 lines
2.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
// Private, no-network config shape probe. Never install under server/public.
|
|
ini_set('display_errors', '0');
|
|
ini_set('log_errors', '0');
|
|
if (PHP_SAPI !== 'cli' && (PHP_SAPI !== 'cgi-fcgi' || ($_SERVER['REMOTE_ADDR'] ?? '') !== '127.0.0.1')) {
|
|
http_response_code(403); exit;
|
|
}
|
|
header('Content-Type: application/json');
|
|
try {
|
|
$root = dirname(__DIR__) . '/server';
|
|
require $root . '/vendor/autoload.php';
|
|
$app = new \think\App($root . '/');
|
|
require_once $root . '/vendor/topthink/framework/src/helper.php';
|
|
$app->env->load($root . '/.env');
|
|
$cfg = require $root . '/config/prescription_ai.php';
|
|
$app->config->set($cfg, 'prescription_ai');
|
|
$ca = $cfg['required_attachment_upload']['ca_file'] ?? null;
|
|
$base = $cfg['base_url'] ?? null;
|
|
$parse = is_string($base) ? parse_url($base) : false;
|
|
$out = [
|
|
'ok' => true, 'sapi' => PHP_SAPI, 'curl_loaded' => extension_loaded('curl'),
|
|
'enabled' => ($cfg['enable'] ?? null) === true,
|
|
'base_url_present' => is_string($base) && $base !== '',
|
|
'base_url_valid' => is_string($base) && filter_var($base, FILTER_VALIDATE_URL) !== false,
|
|
'base_has_control_or_space_or_backslash' => is_string($base) && preg_match('/[\x00-\x20\x7f\\\\]/', $base) !== 0,
|
|
'base_forbidden_parts' => !is_array($parse) || count(array_intersect(['user', 'pass', 'query', 'fragment'], array_keys($parse))) > 0,
|
|
'base_path_valid' => is_array($parse) && preg_match('~\A(?:/[A-Za-z0-9_-]+)*/?\z~', $parse['path'] ?? '') === 1,
|
|
'ca_string' => is_string($ca), 'ca_present' => is_string($ca) && $ca !== '',
|
|
'ca_has_control' => is_string($ca) && preg_match('/[\x00-\x1f\x7f]/', $ca) !== 0,
|
|
'ca_file_exists' => is_string($ca) && is_file($ca),
|
|
'ca_file_readable' => is_string($ca) && is_readable($ca),
|
|
'ca_matches_curl_ini' => is_string($ca) && $ca === (string) ini_get('curl.cainfo'),
|
|
'curl_ini_ca_present' => (string) ini_get('curl.cainfo') !== '',
|
|
'curl_ini_ca_readable' => (string) ini_get('curl.cainfo') !== '' && is_readable((string) ini_get('curl.cainfo')),
|
|
'openssl_ini_ca_present' => (string) ini_get('openssl.cafile') !== '',
|
|
'openssl_ini_ca_readable' => (string) ini_get('openssl.cafile') !== '' && is_readable((string) ini_get('openssl.cafile')),
|
|
'model_keys' => [],
|
|
];
|
|
foreach (['qwen', 'openai'] as $profile) {
|
|
$key = $cfg['models'][$profile]['api_key'] ?? null;
|
|
$out['model_keys'][$profile] = ['present' => is_string($key) && $key !== '',
|
|
'valid_format' => is_string($key) && $key !== '' && strlen($key) <= 4096 && preg_match('/[^\x21-\x7e]/', $key) === 0];
|
|
}
|
|
echo json_encode($out, JSON_THROW_ON_ERROR);
|
|
} catch (\Throwable $ignored) {
|
|
echo '{"ok":false,"error_code":"CONFIG_DIAGNOSTIC_FAILED"}';
|
|
}
|