Initialize standalone EzServer for macOS

This commit is contained in:
SantaSpeen committed 2026-11-22 02:15:29 +03:00
commit cf192a5f3c
11 files changed
+680

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
"""Extract the EzServer cabinet records from a 7-Zip InstallShield overlay."""
from pathlib import Path
import shutil
import sys
CABINETS = {b"data1.hdr", b"data1.cab", b"data2.cab"}
def read_field(stream):
value = bytearray()
for _ in range(1024):
byte = stream.read(1)
if byte == b"\0":
return bytes(value)
if not byte:
break
value.extend(byte)
raise ValueError("Incomplete InstallShield record")
def extract(overlay, output):
missing = CABINETS.copy()
with overlay.open("rb") as stream:
while missing:
name = read_field(stream)
read_field(stream) # Path on the installation media.
read_field(stream) # File version.
size = int(read_field(stream))
end = stream.tell() + size
if size < 0 or end > overlay.stat().st_size:
raise ValueError("Invalid InstallShield record size")
if name in missing:
with (output / name.decode("ascii")).open("wb") as destination:
remaining = size
while remaining:
chunk = stream.read(min(remaining, 1024 * 1024))
if not chunk:
raise ValueError("Truncated cabinet")
destination.write(chunk)
remaining -= len(chunk)
missing.remove(name)
stream.seek(end)
def stage_web_service(extracted, runtime):
source = extracted / "www" / "ezwebserver" / "src"
destination = runtime / "www" / "ezwebserver" / "src"
for folder in ("application", "public", "vendor"):
shutil.copytree(
source / folder,
destination / folder,
ignore=shutil.ignore_patterns(
"*.exe", "*.dll", "*.bat", "*.cmd", "*.msi", "dbconfig.ini", "config_base.ini"
),
)
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")
if __name__ == "__main__":
if sys.argv[1] == "cabinet":
extract(Path(sys.argv[2]), Path(sys.argv[3]))
elif sys.argv[1] == "stage":
stage_web_service(Path(sys.argv[2]), Path(sys.argv[3]))
else:
raise SystemExit("Unknown extraction operation")
+39
View File
@@ -0,0 +1,39 @@
#!/bin/bash
set -euo pipefail
umask 077
server_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
project_dir="$(dirname "$server_dir")"
installer="${1:-$project_dir/_source/EzServer V4.1.6 Setup.exe}"
runtime="${EZSERVER_RUNTIME:-$project_dir/.build/ezserver-macos/runtime}"
unshield="${EZSERVER_UNSHIELD:-unshield}"
archive_tool="${EZSERVER_7ZIP:-7z}"
if [[ ! -f "$installer" ]]; then
printf 'EzServer installer not found: %s\n' "$installer" >&2
exit 1
fi
for dependency in "$unshield" "$archive_tool" python3; do
if ! command -v "$dependency" >/dev/null; then
printf 'Missing extraction tool: %s\n' "$dependency" >&2
exit 1
fi
done
if [[ -e "$runtime" ]]; then
printf 'EzServer runtime already exists: %s\n' "$runtime" >&2
exit 1
fi
parent="$(dirname "$runtime")"
mkdir -p "$parent"
stage="$(mktemp -d "$parent/.prepare.XXXXXX")"
trap 'rm -rf "$stage"' EXIT
"$archive_tool" e -y "-o$stage" "$installer" '[0]' >/dev/null
python3 "$server_dir/extract-installshield.py" cabinet "$stage/[0]" "$stage"
"$unshield" -g EzWebServer_Install -d "$stage/extracted" x "$stage/data1.cab" > "$stage/extract.log"
mkdir "$stage/runtime"
python3 "$server_dir/extract-installshield.py" stage "$stage/extracted/EzWebServer_Install" "$stage/runtime"
test -f "$stage/runtime/www/ezwebserver/src/public/api/index.php"
test -f "$stage/runtime/www/ezwebserver/src/vendor/autoload.php"
mv "$stage/runtime" "$runtime"
printf '%s\n' "$runtime"
+43
View File
@@ -0,0 +1,43 @@
<?php
// Launch the original API front controller for the verified, database-independent routes.
function failRequest($status, $message)
{
http_response_code($status);
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['error' => $message]);
}
header('Cache-Control: no-store');
$host = $_SERVER['HTTP_HOST'] ?? '';
if (!preg_match('/\A(?:127\.0\.0\.1|localhost)(?::[0-9]{1,5})?\z/i', $host)) {
failRequest(400, 'Use a loopback host');
return;
}
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'GET') {
header('Allow: GET');
failRequest(405, 'Only GET is supported');
return;
}
$runtime = getenv('EZSERVER_RUNTIME');
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
if ($path === '/') {
header('Content-Type: text/html; charset=utf-8');
readfile($runtime . '/index.html');
return;
}
if (!preg_match('~\A/api(?:/index\.php)?(?:/v1/info/(?:versions|versionsbyname))?/?\z~i', $path ?? '')) {
failRequest(404, 'Route is unavailable in the macOS preview');
return;
}
$public = $runtime . '/www/ezwebserver/src/public';
$_SERVER['DOCUMENT_ROOT'] = $public;
$_SERVER['SCRIPT_FILENAME'] = $public . '/api/index.php';
$_SERVER['SCRIPT_NAME'] = '/api/index.php';
$_SERVER['PHP_SELF'] = '/api/index.php';
$_SERVER['CI_ENV'] = 'production';
chdir($public . '/api');
require $_SERVER['SCRIPT_FILENAME'];
Executable
+35
View File
@@ -0,0 +1,35 @@
#!/bin/bash
set -euo pipefail
umask 077
server_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
project_dir="$(dirname "$server_dir")"
runtime="${EZSERVER_RUNTIME:-$project_dir/.build/ezserver-macos/runtime}"
php="${EZSERVER_PHP:-php}"
port="${EZSERVER_PORT:-55005}"
if [[ ! -f "$runtime/www/ezwebserver/src/public/api/index.php" ]]; then
printf '%s\n' 'Prepare the EzServer runtime with server/prepare.sh first.' >&2
exit 1
fi
if ! command -v "$php" >/dev/null; then
printf '%s\n' 'PHP CLI is required. Install PHP or set EZSERVER_PHP to its executable.' >&2
exit 1
fi
if ! [[ "$port" =~ ^[1-9][0-9]{0,4}$ ]] || (( port > 65535 )); then
printf '%s\n' 'EZSERVER_PORT must be between 1 and 65535.' >&2
exit 1
fi
"$php" -r '
foreach (["intl", "mbstring", "session"] as $extension) {
if (!extension_loaded($extension)) {
fwrite(STDERR, "Missing PHP extension: " . $extension . PHP_EOL);
exit(1);
}
}
'
export EZSERVER_RUNTIME="$(cd "$runtime" && pwd)"
mkdir -p "$EZSERVER_RUNTIME/empty"
exec "$php" -d display_errors=0 -d expose_php=0 \
-S "127.0.0.1:$port" -t "$EZSERVER_RUNTIME/empty" "$server_dir/router.php"