config in webui

This commit is contained in:
KOWX712
2025-02-11 13:36:14 +08:00
parent d534185d48
commit 83469179e6
15 changed files with 519 additions and 26 deletions

View File

@@ -41,15 +41,9 @@ migrate_config() {
# Migrate security_patch config*
if [ ! -s "/data/adb/security_patch" ]; then
echo "#Tricky Addon security patch config" > "/data/adb/security_patch"
echo "#Tricky Addon security patch auto config" > "/data/adb/security_patch"
fi
if ! grep -q "^auto_config=" "/data/adb/security_patch"; then
echo "auto_config=1" >> "/data/adb/security_patch"
fi
for value in auto_config custom_config all system vendor boot; do
if ! grep -q "^$value=" "/data/adb/security_patch"; then
if [ "$value" = "auto_config" ]; then
echo "$value=1" >> "/data/adb/security_patch"
else
echo "$value=0" >> "/data/adb/security_patch"
fi
fi
done
}

View File

@@ -48,22 +48,9 @@ set_security_patch() {
fi
}
# Spoof security patch if older than 1 year
# Spoof security patch
if grep -q "^auto_config=1" "/data/adb/security_patch"; then
# Auto config
set_security_patch
elif grep -q "^custom_config=1" "/data/adb/security_patch"; then
# Custom config
if ! grep -q "^all=0" "/data/adb/security_patch"; then
echo "all=$(grep "^all=" "/data/adb/security_patch" | cut -d'=' -f2)" > "$TARGET_DIR/security_patch.txt"
else
> "$TARGET_DIR/security_patch.txt"
for value in system vendor boot; do
if grep -q "^$value=" "/data/adb/security_patch"; then
echo "$value=$(grep "^$value=" "/data/adb/security_patch" | cut -d'=' -f2)" >> "$TARGET_DIR/security_patch.txt"
fi
done
fi
fi
# Reset verified Boot Hash

View File

@@ -12,6 +12,7 @@
<link rel="stylesheet" href="styles/boot-hash.css" type="text/css">
<link rel="stylesheet" href="styles/header.css" type="text/css">
<link rel="stylesheet" href="styles/search_menu.css" type="text/css">
<link rel="stylesheet" href="styles/security-patch.css" type="text/css">
<script type="module" crossorigin src="scripts/main.js"></script>
<script type="module" crossorigin src="scripts/about.js"></script>
<script type="module" crossorigin src="scripts/help.js"></script>
@@ -79,6 +80,7 @@
<li id="validkb" data-i18n="menu.set_valid_keybox"></li>
<li id="customkb" data-i18n="menu.set_custom_keybox"></li>
<li id="boot-hash" data-i18n="menu.set_verified_boot_hash"></li>
<li id="security-patch" data-i18n="menu.set_security_patch"></li>
<li id="about" data-i18n="menu.about"></li>
</ul>
</div>
@@ -193,6 +195,13 @@
</ul>
</li>
<br>
<li id="set_security_patch">
<strong data-i18n="help.set_security_patch"></strong>
<ul>
<li data-i18n="help.set_security_patch_description"></li>
</ul>
</li>
<br>
<li id="set_verified_boot_hash">
<strong data-i18n="help.set_verified_boot_hash"></strong>
<ul>
@@ -283,6 +292,44 @@
<span data-i18n="functional_button.uninstall_webui"></span>
</div>
</div>
<!-- Security Patch Overlay -->
<div id="security-patch-overlay" class="security-patch-overlay"></div>
<div id="security-patch-card" class="security-patch-card">
<div class="security-patch-content">
<div class="advanced-toggle">
<input type="checkbox" id="advanced-mode" class="advanced-checkbox">
<label for="advanced-mode" data-i18n="security_patch.advanced_mode">Advanced Mode</label>
</div>
<div id="normal-mode-inputs" class="normal-mode-inputs">
<div class="input-group">
<label id="security_patch-all">All</label>
<input type="text" id="all-patch" placeholder="20250101" maxlength="8">
</div>
</div>
<div id="advanced-mode-inputs" class="advanced-mode-inputs hidden">
<div class="input-group">
<label id="security_patch-boot">Boot</label>
<input type="text" id="boot-patch" placeholder="202501">
</div>
<div class="input-group">
<label id="security_patch-system">System</label>
<input type="text" id="system-patch" placeholder="2025-01-01">
</div>
<div class="input-group">
<label id="security_patch-vendor">Vendor</label>
<input type="text" id="vendor-patch" placeholder="2025-01-01">
</div>
</div>
<div class="button-container">
<button id="auto-config" class="auto-button" data-i18n="security_patch.auto">Auto</button>
<button id="save-patch" class="save-button" data-i18n="security_patch.save">Save</button>
</div>
</div>
</div>
</body>
</html>

View File

@@ -19,6 +19,8 @@
"set_keybox_description": "Replace tricky store keybox.xml. AOSP keybox will be replaced if there's no more valid keybox. Valid keybox option requires Internet connection.",
"set_custom_keybox": "Set Custom Keybox",
"set_custom_keybox_description": "Import keybox from your device storage. Only support xml file.",
"set_security_patch": "Set Security Patch",
"set_security_patch_description": "Set custom security patch spoof. Auto config will use security patch from PIF module, enabled by default. Leave blank and save to disable auto config.",
"set_verified_boot_hash": "Set Verified Boot Hash",
"set_verified_boot_hash_description": "Get verifiedBootHash value from Key Attestation Demo. Fix abnormal boot state by resetting ro.boot.vbmeta.digest."
},
@@ -49,6 +51,7 @@
"set_valid_keybox": "Set Valid Keybox",
"set_custom_keybox": "Set Custom Keybox",
"set_verified_boot_hash": "Set Verified Boot Hash",
"set_security_patch": "Set Security Patch",
"about": "About"
},
"reset_vbmeta": {
@@ -88,5 +91,19 @@
"custom_key_set": "Custom keybox set successfully",
"custom_key_set_error": "Failed to set custom keybox",
"no_file_selected": "No file selected"
},
"security_patch": {
"advanced_mode": "Advanced Mode",
"auto": "Auto",
"save": "Save",
"auto_success": "Auto config enabled successfully, reboot to apply.",
"auto_failed": "Failed to enable auto config",
"save_success": "Security patch saved successfully",
"save_failed": "Failed to save security patch",
"value_empty": "Value cannot be empty",
"invalid_all": "Invalid format.",
"invalid_boot": "Invalid boot format.",
"invalid_system": "Invalid system format.",
"invalid_vendor": "Invalid vendor format."
}
}

View File

@@ -19,6 +19,8 @@
"set_keybox_description": "Replace tricky store keybox.xml. AOSP keybox will be replaced if there's no more valid keybox. Valid keybox option requires Internet connection.",
"set_custom_keybox": "Set Custom Keybox",
"set_custom_keybox_description": "Import keybox from your device storage. Only support xml file.",
"set_security_patch": "Set Security Patch",
"set_security_patch_description": "Set custom security patch spoof. Auto config will use security patch from PIF module, enabled by default. Leave blank and save to disable auto config.",
"set_verified_boot_hash": "Set Verified Boot Hash",
"set_verified_boot_hash_description": "Get verifiedBootHash value from Key Attestation Demo. Fix abnormal boot state by resetting ro.boot.vbmeta.digest."
},
@@ -49,6 +51,7 @@
"set_valid_keybox": "Set Valid Keybox",
"set_custom_keybox": "Set Custom Keybox",
"set_verified_boot_hash": "Set Verified Boot Hash",
"set_security_patch": "Set Security Patch",
"about": "About"
},
"reset_vbmeta": {
@@ -88,5 +91,19 @@
"custom_key_set": "Custom keybox set successfully",
"custom_key_set_error": "Failed to set custom keybox",
"no_file_selected": "No file selected"
},
"security_patch": {
"advanced_mode": "Advanced Mode",
"auto": "Auto",
"save": "Save",
"auto_success": "Auto config enabled successfully, reboot to apply.",
"auto_failed": "Failed to enable auto config",
"save_success": "Security patch saved successfully",
"save_failed": "Failed to save security patch",
"value_empty": "Value cannot be empty",
"invalid_all": "Invalid format.",
"invalid_boot": "Invalid boot format.",
"invalid_system": "Invalid system format.",
"invalid_vendor": "Invalid vendor format."
}
}

View File

@@ -19,6 +19,8 @@
"set_keybox_description": "Reemplazar el archivo keybox.xml de Tricky Store. El AOSP Keybox será reemplazado si no hay un keybox válido. Esta opción requiere conexión a Internet.",
"set_custom_keybox": "Establecer Keybox Personalizado",
"set_custom_keybox_description": "Importar keybox desde el almacenamiento de tu dispositivo. Solo soporta archivos xml.",
"set_security_patch": "Configurar Parche de Seguridad",
"set_security_patch_description": "Configurar parche de seguridad personalizado. La configuración automática usará el parche de seguridad de PIF, habilitado por defecto. Deja en blanco y guarda para deshabilitar la configuración automática.",
"set_verified_boot_hash": "Configurar Boot Hash Verificado",
"set_verified_boot_hash_description": "Obtén el valor de verifiedBootHash del Key Attestation Demo. Corrige un estado de arranque anormal reiniciando ro.boot.vbmeta.digest."
},
@@ -48,6 +50,7 @@
"set_aosp_keybox": "Configurar AOSP Keybox",
"set_valid_keybox": "Configurar Keybox Válido",
"set_custom_keybox": "Establecer Keybox Personalizado",
"set_security_patch": "Configurar Parche de Seguridad",
"set_verified_boot_hash": "Configurar Boot Hash Verificado",
"about": "Acerca de"
},
@@ -57,7 +60,7 @@
},
"about": {
"module_name_line1": "Tricky Addon",
"module_name_line2": "Update Target List",
"module_name_line2": "Actualizar Lista de Objetivos",
"by": "por",
"telegram_channel": "Canal de Telegram",
"github": "GitHub",
@@ -88,5 +91,19 @@
"custom_key_set": "Keybox personalizado establecido con éxito",
"custom_key_set_error": "Error al establecer el keybox personalizado",
"no_file_selected": "Ningún archivo seleccionado"
},
"security_patch": {
"advanced_mode": "Modo Avanzado",
"auto": "Automático",
"save": "Guardar",
"auto_success": "Configuración automática habilitada con éxito, reinicia para aplicar.",
"auto_failed": "Error al habilitar la configuración automática",
"save_success": "Parche de seguridad guardado con éxito",
"save_failed": "Error al guardar el parche de seguridad",
"value_empty": "El valor no puede estar vacío",
"invalid_all": "Formato inválido.",
"invalid_boot": "Formato de arranque inválido.",
"invalid_system": "Formato de sistema inválido.",
"invalid_vendor": "Formato de proveedor inválido."
}
}

View File

@@ -19,6 +19,8 @@
"set_keybox_description": "Tricky Store の keybox.xml を置き換えます。有効な Keybox がなくなった場合は、AOSP Keybox に置き換えられます。インターネット接続が必要です。",
"set_custom_keybox": "カスタム Keybox を設定",
"set_custom_keybox_description": "デバイスのストレージからカスタム Keybox ファイルをインポートします。xml ファイルのみ対応。",
"set_security_patch": "セキュリティパッチを設定",
"set_security_patch_description": "カスタムセキュリティパッチの設定。自動設定は PIF モジュールのセキュリティパッチを使用します。空白のまま保存すると自動設定を無効にします。",
"set_verified_boot_hash": "確認付きブートハッシュを設定",
"set_verified_boot_hash_description": "Key Attestation Demo から確認付きブートハッシュの値を取得します。ro.boot.vbmeta.digest をリセットして異常なブート状態を修正します。"
},
@@ -49,6 +51,7 @@
"set_valid_keybox": "有効な Keybox を設定",
"set_custom_keybox": "カスタム Keybox を設定",
"set_verified_boot_hash": "確認付きブートハッシュを設定",
"set_security_patch": "セキュリティパッチを設定",
"about": "このアドオンについて"
},
"reset_vbmeta": {
@@ -88,5 +91,19 @@
"custom_key_set": "カスタム Keybox の設定に成功しました",
"custom_key_set_error": "カスタム Keybox の設定に失敗しました",
"no_file_selected": "ファイルが選択されていません"
},
"security_patch": {
"advanced_mode": "高度なモード",
"auto": "自動",
"save": "保存",
"auto_success": "自動設定が正常に有効になりました。適用するには再起動してください。",
"auto_failed": "自動設定を有効にできませんでした",
"save_success": "セキュリティパッチが正常に保存されました",
"save_failed": "セキュリティパッチの保存に失敗しました",
"value_empty": "値は空にできません",
"invalid_all": "無効な形式です。",
"invalid_boot": "無効なブート形式です。",
"invalid_system": "無効なシステム形式です。",
"invalid_vendor": "無効なベンダー形式です。"
}
}

View File

@@ -19,6 +19,8 @@
"set_keybox_description": "Замените tricky store keybox.xml. AOSP keybox будет заменен, если не будет найден действующий keybox. Опция с действующим keybox требует подключения к интернету.",
"set_custom_keybox": "Установить пользовательский Keybox",
"set_custom_keybox_description": "Импортируйте файл keybox из вашего устройства в хранилище. Поддерживаются только xml файлы.",
"set_security_patch": "Установить Security Patch",
"set_security_patch_description": "Установите пользовательский патч безопасности. Автоматическая настройка будет использовать патч безопасности из модуля PIF, включен по умолчанию. Оставьте пустым и сохраните, чтобы отключить автоматическую настройку.",
"set_verified_boot_hash": "Установить Verified Boot Hash",
"set_verified_boot_hash_description": "Получите значение verifiedBootHash из Key Attestation Demo. Исправьте аномальное состояние загрузки, сбросив ro.boot.vbmeta.digest."
},
@@ -48,6 +50,7 @@
"set_aosp_keybox": "Установить AOSP Keybox",
"set_valid_keybox": "Установить действующий Keybox",
"set_custom_keybox": "Установить пользовательский Keybox",
"set_security_patch": "Установить Security Patch",
"set_verified_boot_hash": "Установить Verified Boot Hash",
"about": "О программе"
},
@@ -88,5 +91,19 @@
"custom_key_set": "Пользовательский keybox успешно установлен",
"custom_key_set_error": "Не удалось установить пользовательский keybox",
"no_file_selected": "Файл не выбран"
},
"security_patch": {
"advanced_mode": "Расширенный режим",
"auto": "Авто",
"save": "Сохранить",
"auto_success": "Автоматическая конфигурация успешно включена, перезагрузите для применения.",
"auto_failed": "Не удалось включить автоматическую конфигурацию",
"save_success": "Патч безопасности успешно сохранен",
"save_failed": "Не удалось сохранить патч безопасности",
"value_empty": "Значение не может быть пустым",
"invalid_all": "Неверный формат.",
"invalid_boot": "Неверный формат загрузки.",
"invalid_system": "Неверный формат системы.",
"invalid_vendor": "Неверный формат поставщика."
}
}

View File

@@ -19,6 +19,8 @@
"set_keybox_description": "Palitan ang tricky store keybox. Palitan ang AOSP keybox kung walang valid keybox. Nangangailangan ng koneksyon sa internet ang valid keybox option.",
"set_custom_keybox": "I-set ang Custom Keybox",
"set_custom_keybox_description": "Mag-import ng custom keybox mula sa iyong device storage. Sumusuporta lamang ng xml file.",
"set_security_patch": "I-set ang Security Patch",
"set_security_patch_description": "I-set ang custom security patch. Ang auto config ay mag-use ng security patch mula sa PIF module, default enabled. I-leave blank at i-save para i-disable ang auto config.",
"set_verified_boot_hash": "I-set ang Verified Boot Hash",
"set_verified_boot_hash_description": "Kunin ang verifiedBootHash mula sa Key Attestation Demo. Ayusin ang abnormal na boot state sa pamamagitan ng pag-reset ng ro.boot.vbmeta.digest."
},
@@ -49,6 +51,7 @@
"set_valid_keybox": "I-set ang Valid Keybox",
"set_custom_keybox": "I-set ang Custom Keybox",
"set_verified_boot_hash": "I-set ang Verified Boot Hash",
"set_security_patch": "I-set ang Security Patch",
"about": "Tungkol"
},
"reset_vbmeta": {
@@ -88,5 +91,19 @@
"custom_key_set": "Matagumpay na na-set ang Custom Keybox",
"custom_key_set_error": "Nabigong i-set ang Custom Keybox",
"no_file_selected": "Walang napiling file"
},
"security_patch": {
"advanced_mode": "Advanced Mode",
"auto": "Auto",
"save": "I-save",
"auto_success": "Matagumpay na na-enable ang auto config, mag-reboot upang i-apply.",
"auto_failed": "Nabigong i-enable ang auto config",
"save_success": "Matagumpay na na-save ang security patch",
"save_failed": "Nabigong i-save ang security patch",
"value_empty": "Hindi pwedeng walang laman ang value",
"invalid_all": "Invalid format.",
"invalid_boot": "Invalid boot format.",
"invalid_system": "Invalid system format.",
"invalid_vendor": "Invalid vendor format."
}
}

View File

@@ -19,6 +19,8 @@
"set_keybox_description": "Tricky Store'daki keybox.xml dosyasını değiştirir. Eğer geçerli bir keybox yoksa AOSP keybox ile değiştirilecektir. Geçerli keybox seçeneği internet bağlantısı gerektirir.",
"set_custom_keybox": "Özel Keybox Ayarla",
"set_custom_keybox_description": "Cihaz depolamasından bir keybox dosyasını içe aktarın. Sadece xml dosyaları desteklenir.",
"set_security_patch": "Güvenlik Parçası Ayarla",
"set_security_patch_description": "Özel güvenlik parçasını ayarlayın. Otomatik yapılandırma PIF modülünün güvenlik parçasını kullanacaktır. Boş bırakın ve kaydedin ki otomatik yapılandırma devre dışı bırakılsın.",
"set_verified_boot_hash": "Doğrulanmış Boot Hash Ayarla",
"set_verified_boot_hash_description": "Key Attestation Demo'dan verifiedBootHash değerini alın. Abnormal boot durumunu ro.boot.vbmeta.digest'i sıfırlayarak düzeltin."
},
@@ -48,6 +50,7 @@
"set_aosp_keybox": "AOSP Keybox Ayarla",
"set_valid_keybox": "Geçerli Keybox Ayarla",
"set_custom_keybox": "Özel Keybox Ayarla",
"set_security_patch": "Güvenlik Parçası Ayarla",
"set_verified_boot_hash": "Doğrulanmış Boot Hash Ayarla",
"about": "Hakkında"
},
@@ -88,5 +91,19 @@
"custom_key_set": "Özel keybox başarıyla ayarlandı",
"custom_key_set_error": "Özel keybox ayarlanamadı",
"no_file_selected": "Dosya seçilmedi"
},
"security_patch": {
"advanced_mode": "Gelişmiş Mod",
"auto": "Otomatik",
"save": "Kaydet",
"auto_success": "Otomatik yapılandırma başarıyla etkinleştirildi, yeniden başlatın.",
"auto_failed": "Otomatik yapılandırma etkinleştirilemedi",
"save_success": "Güvenlik parçası başarıyla kaydedildi",
"save_failed": "Güvenlik parçası kaydedilemedi",
"value_empty": "Değer boş olamaz",
"invalid_all": "Geçersiz format",
"invalid_boot": "Geçersiz başlatma formatı",
"invalid_system": "Geçersiz sistem formatı",
"invalid_vendor": "Geçersiz sağlayıcı formatı"
}
}

View File

@@ -19,6 +19,8 @@
"set_keybox_description": "替换 Tricky Store 的密钥keybox.xml。如果没有有效密钥将替换为 AOSP 密钥。有效密钥选项需连网使用。",
"set_custom_keybox": "设置自定义密钥",
"set_custom_keybox_description": "从设备存储导入自定义密钥。仅支持 xml 文件。",
"set_security_patch": "设置安全补丁",
"set_security_patch_description": "设置自定义安全补丁。自动配置将使用 PIF 模块的安全补丁,默认启用。留空保存则禁用自动配置。",
"set_verified_boot_hash": "设置哈希值",
"set_verified_boot_hash_description": "从 Key Attestation Demo 获取 verifiedBootHash哈希值。通过重置 ro.boot.vbmeta.digest 修复异常 boot 状态。"
},
@@ -48,6 +50,7 @@
"set_aosp_keybox": "设置 AOSP 密钥",
"set_valid_keybox": "设置有效密钥",
"set_custom_keybox": "设置自定义密钥",
"set_security_patch": "设置安全补丁",
"set_verified_boot_hash": "设置哈希值",
"about": "关于"
},
@@ -88,5 +91,19 @@
"custom_key_set": "成功设置自定义密钥",
"custom_key_set_error": "设置自定义密钥失败",
"no_file_selected": "未选择文件"
},
"security_patch": {
"advanced_mode": "高级模式",
"auto": "自动",
"save": "保存",
"auto_success": "自动配置成功启用,重启生效。",
"auto_failed": "无法启用自动配置",
"save_success": "安全补丁成功保存",
"save_failed": "保存安全补丁失败",
"value_empty": "值不能为空",
"invalid_all": "无效格式。",
"invalid_boot": "无效启动格式。",
"invalid_system": "无效系统格式。",
"invalid_vendor": "无效供应商格式。"
}
}

View File

@@ -19,6 +19,8 @@
"set_keybox_description": "替換 Tricky Store 的密鑰keybox.xml。如果沒有有效密鑰將替換為 AOSP 密鑰。有效密鑰選項需連網使用。",
"set_custom_keybox": "設置自定義密鑰",
"set_custom_keybox_description": "從設備存儲導入自定義密鑰。僅支持 xml 文件。",
"set_security_patch": "設置安全補丁",
"set_security_patch_description": "設置自定義安全補丁。自動配置將使用 PIF 模組的安全補丁,預設啟用。留空保存則禁用自動配置。",
"set_verified_boot_hash": "設置哈希值",
"set_verified_boot_hash_description": "從 Key Attestation Demo 獲取 verifiedBootHash哈希值。通過重置 ro.boot.vbmeta.digest 修復異常 boot 狀態。"
},
@@ -48,6 +50,7 @@
"set_aosp_keybox": "設置 AOSP 密鑰",
"set_valid_keybox": "設置有效密鑰",
"set_custom_keybox": "設置自定義密鑰",
"set_security_patch": "設置安全補丁",
"set_verified_boot_hash": "設置哈希值",
"about": "關於"
},
@@ -88,5 +91,19 @@
"custom_key_set": "成功設置自定義密鑰",
"custom_key_set_error": "設置自定義密鑰失敗",
"no_file_selected": "未選擇文件"
},
"security_patch": {
"advanced_mode": "進階模式",
"auto": "自動",
"save": "保存",
"auto_success": "自動配置成功啟用,重啟生效。",
"auto_failed": "無法啟用自動配置",
"save_success": "安全補丁成功保存",
"save_failed": "保存安全補丁失敗",
"value_empty": "值不能為空",
"invalid_all": "無效格式。",
"invalid_boot": "無效啟動格式。",
"invalid_system": "無效系統格式。",
"invalid_vendor": "無效供應商格式。"
}
}

View File

@@ -3,6 +3,7 @@ import { initializeAvailableLanguages, detectUserLanguage, loadTranslations, set
import { aospkb } from './menu_option.js';
import { searchMenuContainer, searchInput, clearBtn, setupMenuToggle } from './search_menu.js';
import { updateCheck } from './update.js';
import { securityPatch } from './security_patch.js';
// Header Elements
const headerBlock = document.querySelector('.header-block');
@@ -20,7 +21,7 @@ export const basePath = "set-path";
export const appsWithExclamation = [];
export const appsWithQuestion = [];
const ADDITIONAL_APPS = [ "android", "com.android.vending", "com.google.android.gms", "io.github.vvb2060.keyattestation", "io.github.vvb2060.mahoshojo", "icu.nullptr.nativetest" ]; // Always keep default apps in target.txt
const rippleClasses = ['.language-option', '.menu-button', '.menu-options li', '.search-card', '.card', '.update-card', '.link-icon', '.floating-btn', '.uninstall-container', '.boot-hash-save-button', '.boot-hash-value', '.reboot', '.install', '.file-item'];
const rippleClasses = ['.language-option', '.menu-button', '.menu-options li', '.search-card', '.card', '.update-card', '.link-icon', '.floating-btn', '.uninstall-container', '.boot-hash-save-button', '.boot-hash-value', '.reboot', '.install', '.file-item', '.save-button', '.auto-button'];
// Variables
let e = 0;
@@ -306,6 +307,7 @@ document.addEventListener('DOMContentLoaded', async () => {
applyRippleEffect();
checkMagisk();
updateCheck();
securityPatch();
loadingIndicator.style.display = "none";
floatingBtn.style.opacity = '1';
setTimeout(() => {

View File

@@ -0,0 +1,201 @@
import { execCommand, showPrompt } from './main.js';
const overlay = document.getElementById('security-patch-overlay');
const card = document.getElementById('security-patch-card');
const advancedToggle = document.getElementById('advanced-mode');
const normalInputs = document.getElementById('normal-mode-inputs');
const advancedInputs = document.getElementById('advanced-mode-inputs');
const allPatchInput = document.getElementById('all-patch');
const bootPatchInput = document.getElementById('boot-patch');
const systemPatchInput = document.getElementById('system-patch');
const vendorPatchInput = document.getElementById('vendor-patch');
const autoButton = document.getElementById('auto-config');
const saveButton = document.getElementById('save-patch');
export function showSecurityPatchDialog() {
overlay.style.display = 'block';
card.style.display = 'block';
loadCurrentConfig();
}
// Hide security patch dialog
function hideSecurityPatchDialog() {
overlay.style.display = 'none';
card.style.display = 'none';
}
// Load current configuration
async function loadCurrentConfig() {
try {
const result = await execCommand('cat /data/adb/security_patch');
if (result) {
const lines = result.split('\n');
let autoConfig = '1', allValue = '0', bootValue = '0', systemValue = '0', vendorValue = '0';
for (const line of lines) {
if (line.startsWith('auto_config=')) {
autoConfig = line.split('=')[1];
}
}
if (autoConfig === '1') {
allValue = null;
bootValue = null;
systemValue = null;
vendorValue = null;
overlay.classList.add('hidden');
} else {
// Read values from tricky_store if auto_config is 0
const trickyResult = await execCommand('cat /data/adb/tricky_store/security_patch.txt');
if (trickyResult) {
const trickyLines = trickyResult.split('\n');
for (const line of trickyLines) {
if (line.startsWith('all=')) {
allValue = line.split('=')[1] || null;
if (allValue !== null) allPatchInput.value = allValue;
}
if (line.startsWith('boot=')) {
bootValue = line.split('=')[1] || null;
if (bootValue !== null) bootPatchInput.value = bootValue;
}
if (line.startsWith('system=')) {
systemValue = line.split('=')[1] || null;
if (systemValue !== null) systemPatchInput.value = systemValue;
}
if (line.startsWith('vendor=')) {
vendorValue = line.split('=')[1] || null;
if (vendorValue !== null) vendorPatchInput.value = vendorValue;
}
}
}
overlay.classList.add('hidden');
}
// Check if in advanced mode
if (autoConfig === '0' && allValue === null && (bootValue || systemValue || vendorValue)) {
advancedToggle.checked = true;
normalInputs.classList.add('hidden');
advancedInputs.classList.remove('hidden');
}
}
} catch (error) {
console.error('Failed to load security patch config:', error);
}
}
// Validate date format YYYY-MM-DD
function isValidDateFormat(date) {
if (date === 'no') return true;
const regex = /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/;
return regex.test(date);
}
// Validate 6-digit format YYYYMM
function isValid6Digit(value) {
if (value === 'prop') return true;
const regex = /^\d{6}$/;
return regex.test(value);
}
// Validate 8-digit format YYYYMMDD
function isValid8Digit(value) {
const regex = /^\d{8}$/;
return regex.test(value);
}
// Initialize event listeners
export function securityPatch() {
document.getElementById("security-patch").addEventListener("click", showSecurityPatchDialog);
// Toggle advanced mode
advancedToggle.addEventListener('change', () => {
normalInputs.classList.toggle('hidden');
advancedInputs.classList.toggle('hidden');
});
// Close on overlay click
overlay.addEventListener('click', (e) => {
if (e.target === overlay) {
hideSecurityPatchDialog();
}
});
// Auto config button
autoButton.addEventListener('click', async () => {
try {
await execCommand(`sed -i "s/^auto_config=.*/auto_config=1/" /data/adb/security_patch`);
showPrompt('security_patch.auto_success');
} catch (error) {
showPrompt('security_patch.auto_failed');
}
hideSecurityPatchDialog();
loadCurrentConfig();
});
// Save button
saveButton.addEventListener('click', async () => {
if (!advancedToggle.checked) {
// Normal mode validation
const allValue = allPatchInput.value.trim();
if (!allValue) {
showPrompt('security_patch.value_empty');
return;
}
if (!isValid8Digit(allValue)) {
showPrompt('security_patch.invalid_all');
return;
}
try {
await execCommand(`
sed -i "s/^auto_config=.*/auto_config=0/" /data/adb/security_patch
echo all=${allValue} > /data/adb/tricky_store/security_patch.txt
`);
showPrompt('security_patch.save_success');
} catch (error) {
showPrompt('security_patch.save_failed');
}
} else {
// Advanced mode validation
const bootValue = bootPatchInput.value.trim();
const systemValue = systemPatchInput.value.trim();
const vendorValue = vendorPatchInput.value.trim();
if (!bootValue && !systemValue && !vendorValue) {
showPrompt('security_patch.value_empty');
return;
}
if (bootValue && !isValid6Digit(bootValue)) {
showPrompt('security_patch.invalid_boot');
return;
}
if (systemValue && !isValidDateFormat(systemValue)) {
showPrompt('security_patch.invalid_system');
return;
}
if (vendorValue && !isValidDateFormat(vendorValue)) {
showPrompt('security_patch.invalid_vendor');
return;
}
try {
const config = [
bootValue ? `boot=${bootValue}` : '',
systemValue ? `system=${systemValue}` : '',
vendorValue ? `vendor=${vendorValue}` : ''
].filter(Boolean);
await execCommand(`
sed -i "s/^auto_config=.*/auto_config=0/" /data/adb/security_patch
echo "${config.join(' ')}" > /data/adb/tricky_store/security_patch.txt
`);
showPrompt('security_patch.save_success');
hideSecurityPatchDialog();
} catch (error) {
showPrompt('security_patch.save_failed');
}
}
hideSecurityPatchDialog();
loadCurrentConfig();
});
}

View File

@@ -0,0 +1,109 @@
.security-patch-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 2000;
}
.security-patch-card {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 20px;
border-radius: 15px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
z-index: 2001;
width: calc(90% - 40px);
max-width: 400px;
}
.security-patch-content {
display: flex;
flex-direction: column;
gap: 20px;
}
.advanced-toggle {
display: flex;
align-items: center;
gap: 8px;
}
.input-group {
display: flex;
flex-direction: column;
gap: 8px;
}
.input-group label {
padding-top: 10px;
font-size: 14px;
color: #666;
}
.input-group input {
padding: 15px;
border: 1px solid #ddd;
outline-color: #007bff;
border-radius: 10px;
font-size: 16px;
}
.button-container {
display: flex;
gap: 10px;
justify-content: flex-end;
margin-top: 10px;
}
.auto-button, .save-button {
padding: 10px 20px;
border: none;
border-radius: 12px;
font-size: 18px;
font-weight: bold;
position: relative;
overflow: hidden;
}
.auto-button {
background-color: #6E6E6E;
color: white;
}
.save-button {
background-color: #007bff;
color: white;
}
.hidden {
display: none;
}
@media (prefers-color-scheme: dark) {
.security-patch-overlay {
background-color: rgba(0, 0, 0, 0.8);
}
.security-patch-card {
background-color: #343434;
color: white;
}
.input-group label {
color: #ccc;
}
.input-group input {
background-color: #343434;
color: #fff;
border: 1px solid #6E6E6E;
}
}