ChatGPT's update to harden software and run db updates.

This commit is contained in:
2026-10-21 06:53:45 -04:00
parent 1e63076123
commit acc8cb70f5
171 changed files with 9325 additions and 404 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
/** The same rules apply to create and edit, regardless of browser validation. */
final class MaintenanceValidation {
private static function text(array $input, string $field, string $label, int $limit, bool $required = false, bool $singleLine = false): string {
$value = $input[$field] ?? '';
if (!is_string($value) || !mb_check_encoding($value, 'UTF-8') || str_contains($value, "\0"))
throw new AppException($label . ' must contain valid text.');
$value = trim($value);
if ($required && ($value === '' || preg_match('/\A[\s\p{Z}]*\z/u', $value)))
throw new AppException($label . ' is required.');
if (mb_strlen($value, 'UTF-8') > $limit)
throw new AppException($label . ' must be ' . $limit . ' characters or fewer.');
if ($singleLine && preg_match('/[\x00-\x1f\x7f]/u', $value))
throw new AppException($label . ' must be a single line.');
return $value;
}
private static function timestamp(array $input, string $prefix, string $label): string {
$date = self::text($input, $prefix . '_date', $label . ' date', 10, true, true);
$time = self::text($input, $prefix . '_time', $label . ' time', 5, true, true);
$value = $date . ' ' . $time;
if (!preg_match('/\A[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}\z/', $value))
throw new AppException($label . ' must use a valid YYYY-MM-DD date and HH:MM time.');
$parsed = DateTimeImmutable::createFromFormat('!Y-m-d H:i', $value, new DateTimeZone(Base::TIMEZONE));
$errors = DateTimeImmutable::getLastErrors();
if (!$parsed || ($errors && ($errors['warning_count'] || $errors['error_count'])) || $parsed->format('Y-m-d H:i') !== $value || $date < '1000-01-01')
throw new AppException($label . ' date/time is invalid.');
return $value;
}
public static function alert(array $input): array {
$title = self::text($input, 'alert_title', 'Alert title', 100, true, true);
$starts = self::timestamp($input, 'alert_starts', 'Start');
$expires = self::timestamp($input, 'alert_expires', 'Expiration');
if ($expires < $starts)
throw new AppException('Expiration cannot be before the start.');
return ['title' => $title, 'starts' => $starts, 'expires' => $expires, 'message' => self::text($input, 'alert_message', 'Alert message', 1000)];
}
public static function popover(array $input): array {
return ['name' => self::text($input, 'popover_name', 'Popover name', 100, true, true), 'title' => self::text($input, 'popover_title', 'Popover title', 100, true, true), 'placeholder' => self::text($input, 'popover_placeholder', 'Popover placeholder', 100, false, true), 'text' => self::text($input, 'popover_text', 'Popover text', 1000)];
}
}