Simplify EzServer menu and serve original Web Console

This commit is contained in:
SantaSpeen committed 2026-11-22 03:12:27 +03:00
1 parent ee7e18490f
commit d748f7cc69
16 files changed
+290 -245

No files matched your search

+4 -1
View File
@@ -55,7 +55,10 @@ def stage_web_service(extracted, runtime):
)
for name in ("application/cache/sessions", "application/logs"):
(destination / name).mkdir(parents=True, exist_ok=True)
shutil.copy2(extracted / "webapps" / "index.html", runtime / "index.html")
webapps = extracted / "webapps"
shutil.copy2(webapps / "index.html", runtime / "index.html")
shutil.copytree(webapps / "webconsole", runtime / "webconsole",
ignore=shutil.ignore_patterns("*.map"))
if __name__ == "__main__":
+35
View File
@@ -0,0 +1,35 @@
<?php
// Initialize the original PHP API database. The Swift database uses a separate schema.
if (PHP_SAPI !== 'cli' || $argc !== 2) {
exit(1);
}
umask(0077);
try {
$db = new PDO('sqlite:' . $argv[1], null, null, [PDO::ATTR_TIMEOUT => 5]);
$db->exec('BEGIN IMMEDIATE');
$applicationId = (int) $db->query('PRAGMA application_id')->fetchColumn();
$version = (int) $db->query('PRAGMA user_version')->fetchColumn();
// "EZSV" in SQLite's application header.
if ($applicationId === 1163547478 && $version === 1) {
$db->exec('COMMIT');
exit(0);
}
$objects = (int) $db->query("SELECT count(*) FROM sqlite_schema WHERE name NOT GLOB 'sqlite_*'")->fetchColumn();
if ($applicationId !== 0 || $version !== 0 || $objects !== 0) {
throw new RuntimeException('Expected a new database or an EzServer PHP database at schema version 1.');
}
$schema = file_get_contents(__DIR__ . '/patients.sqlite.sql');
if ($schema === false) {
throw new RuntimeException('Could not read the patient schema.');
}
$db->exec($schema);
$db->exec('PRAGMA application_id = 1163547478');
$db->exec('PRAGMA user_version = 1');
$db->exec('COMMIT');
} catch (Throwable $error) {
// SQLite rolls back an open transaction when the connection closes.
fwrite(STDERR, 'SQLite initialization failed: ' . $error->getMessage() . PHP_EOL);
exit(1);
}
+20
View File
@@ -12,6 +12,26 @@ http {
server_tokens off;
server {
listen 127.0.0.1:@PORT@;
if ($http_host !~* "^(127\.0\.0\.1|localhost)(:[0-9]{1,5})?$") {
return 400;
}
location = /webconsole {
return 302 /webconsole/;
}
location ^~ /webconsole/ {
root @STAGE@;
index index.html;
types {
text/html html;
text/css css;
application/javascript js;
application/json json;
image/x-icon ico;
image/png png;
text/plain txt;
}
try_files $uri $uri/ =404;
}
location / {
fastcgi_param SCRIPT_FILENAME @STAGE@/router.php;
fastcgi_param SCRIPT_NAME /router.php;
+36
View File
@@ -0,0 +1,36 @@
CREATE TABLE e2_pat (
pat_id INTEGER PRIMARY KEY AUTOINCREMENT,
pat_chartno TEXT NOT NULL UNIQUE,
pat_lastname TEXT,
pat_firstname TEXT,
pat_middlename TEXT,
pat_gender TEXT,
pat_birthdate TEXT,
pat_email TEXT,
pat_socialid TEXT,
pat_registered_datetime TEXT,
pat_photo_filename TEXT,
pat_chosung TEXT,
pat_note TEXT,
pat_phone TEXT,
pat_zipcode TEXT,
pat_address TEXT,
pat_mobile TEXT,
pat_source_type TEXT DEFAULT 'Unknown',
pat_source_id TEXT,
pat_last_access TEXT,
pat_user_defined_1 INTEGER,
pat_user_defined_2 INTEGER,
pat_user_defined_3 REAL,
pat_user_defined_4 REAL,
pat_user_defined_5 INTEGER,
pat_user_defined_6 INTEGER,
pat_user_defined_7 TEXT,
pat_user_defined_8 TEXT,
pat_user_defined_9 TEXT,
pat_user_defined_10 BLOB,
pat_job TEXT,
oth_race_id INTEGER,
oth_class_id INTEGER,
pat_last_updated TEXT
);
+2
View File
@@ -7,6 +7,8 @@ listen.mode = 0600
pm = ondemand
pm.max_children = 2
env[EZSERVER_RUNTIME] = $EZSERVER_RUNTIME
env[EZSERVER_SQLITE] = $EZSERVER_SQLITE
env[EZSERVER_JWT_KEY_FILE] = $EZSERVER_JWT_KEY_FILE
php_admin_flag[display_errors] = off
php_admin_flag[expose_php] = off
php_admin_value[session.save_path] = @STAGE@
+4 -2
View File
@@ -1,6 +1,6 @@
<?php
// Launch the original API front controller for the verified, database-independent routes.
// Launch the original API front controller for the verified routes.
function failRequest($status, $message)
{
http_response_code($status);
@@ -28,7 +28,9 @@ if ($path === '/') {
return;
}
if (!preg_match('~\A/api(?:/index\.php)?(?:/v1/(?:auth/ping|info/(?:versions|versionsbyname)))?/?\z~i', $path ?? '')) {
$patientLookup = getenv('EZSERVER_SQLITE')
&& preg_match('~\A/api(?:/index\.php)?/v1/e2ds/patientsbychartno/?\z~i', $path ?? '');
if (!$patientLookup && !preg_match('~\A/api(?:/index\.php)?(?:/v1/(?:auth/ping|info/(?:versions|versionsbyname)))?/?\z~i', $path ?? '')) {
failRequest(404, 'Route is unavailable in the macOS preview');
return;
}
+26
View File
@@ -54,6 +54,32 @@ foreach (["intl", "mbstring", "session", "pdo_sqlite"] as $extension) {
}
}
'
if [[ -n "${EZSERVER_SQLITE:-}" ]]; then
if [[ "$EZSERVER_SQLITE" != /* || "${EZSERVER_JWT_KEY_FILE:-}" != /* ||
! -f "$EZSERVER_JWT_KEY_FILE" || ! -r "$EZSERVER_JWT_KEY_FILE" ]]; then
printf '%s\n' 'Set EZSERVER_SQLITE and EZSERVER_JWT_KEY_FILE to absolute paths.' >&2
exit 1
fi
cp "$EZSERVER_JWT_KEY_FILE" "$stage/jwt-key"
chmod 600 "$stage/jwt-key"
export EZSERVER_JWT_KEY_FILE="$stage/jwt-key"
"$php" -r '
if (strlen(trim(file_get_contents($argv[1]))) < 32) {
fwrite(STDERR, "The JWT signing key must contain at least 32 bytes." . PHP_EOL);
exit(1);
}
' "$EZSERVER_JWT_KEY_FILE"
"$php" "$server_dir/init-sqlite.php" "$EZSERVER_SQLITE"
cp -R "$EZSERVER_RUNTIME" "$stage/runtime"
export EZSERVER_RUNTIME="$stage/runtime"
config="$EZSERVER_RUNTIME/www/ezwebserver/src/application/config/production"
mkdir -p "$config"
cp "$server_dir/sqlite-database.php" "$config/database.php"
cp "$server_dir/sqlite-rest.php" "$config/rest.php"
fi
if [[ -f "$EZSERVER_RUNTIME/webconsole/index.html" ]]; then
ln -s "$EZSERVER_RUNTIME/webconsole" "$stage/webconsole"
fi
"$nginx" -e stderr -p "$stage/" -c nginx.conf -t
"$fpm" -F -y "$stage/php-fpm.conf" &
fpm_pid=$!
+17
View File
@@ -0,0 +1,17 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
$active_group = 'E2DB';
$query_builder = true;
$db['E2DB'] = [
'dbdriver' => 'pdo',
'subdriver' => 'sqlite',
'dsn' => 'sqlite:' . getenv('EZSERVER_SQLITE'),
'db_debug' => false,
'options' => [
// PostgreSQL returns lowercase names for the original models' unquoted columns.
PDO::ATTR_CASE => PDO::CASE_LOWER,
PDO::ATTR_TIMEOUT => 5,
],
];
+6
View File
@@ -0,0 +1,6 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
// Preserve the original JWT validation with a deployment-specific signing key.
$config['jwt_key'] = trim(file_get_contents(getenv('EZSERVER_JWT_KEY_FILE')));