mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
new: remember pwd in mem
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:choice/choice.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:toolbox/core/extension/context/common.dart';
|
import 'package:toolbox/core/extension/context/common.dart';
|
||||||
import 'package:toolbox/core/extension/context/locale.dart';
|
import 'package:toolbox/core/extension/context/locale.dart';
|
||||||
|
import 'package:toolbox/data/res/store.dart';
|
||||||
import 'package:toolbox/view/widget/choice_chip.dart';
|
import 'package:toolbox/view/widget/choice_chip.dart';
|
||||||
import 'package:toolbox/view/widget/tag.dart';
|
import 'package:toolbox/view/widget/tag.dart';
|
||||||
|
|
||||||
@@ -57,17 +58,27 @@ extension DialogX on BuildContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> showPwdDialog(
|
static final _recoredPwd = <String, String>{};
|
||||||
|
|
||||||
|
Future<String?> showPwdDialog({
|
||||||
String? user,
|
String? user,
|
||||||
) async {
|
required String hostId,
|
||||||
|
void Function()? onCorrectPwd,
|
||||||
|
}) async {
|
||||||
if (!mounted) return null;
|
if (!mounted) return null;
|
||||||
return await showRoundDialog<String>(
|
return await showRoundDialog<String>(
|
||||||
title: Text(user ?? l10n.pwd),
|
title: Text(user ?? l10n.pwd),
|
||||||
child: Input(
|
child: Input(
|
||||||
|
controller: TextEditingController(text: _recoredPwd[hostId]),
|
||||||
autoFocus: true,
|
autoFocus: true,
|
||||||
type: TextInputType.visiblePassword,
|
type: TextInputType.visiblePassword,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
onSubmitted: (val) => pop(val.trim()),
|
onSubmitted: (val) {
|
||||||
|
pop(val);
|
||||||
|
if (Stores.setting.rememberPwdInMem.fetch()) {
|
||||||
|
_recoredPwd[hostId] = val;
|
||||||
|
}
|
||||||
|
},
|
||||||
label: l10n.pwd,
|
label: l10n.pwd,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ extension SSHClientX on SSHClient {
|
|||||||
_OnStdout? onStderr,
|
_OnStdout? onStderr,
|
||||||
_OnStdin? stdin,
|
_OnStdin? stdin,
|
||||||
bool redirectToBash = false, // not working yet. do not use
|
bool redirectToBash = false, // not working yet. do not use
|
||||||
|
required String id,
|
||||||
}) async {
|
}) async {
|
||||||
var isRequestingPwd = false;
|
var isRequestingPwd = false;
|
||||||
final session = await exec(
|
final session = await exec(
|
||||||
@@ -80,7 +81,7 @@ extension SSHClientX on SSHClient {
|
|||||||
isRequestingPwd = true;
|
isRequestingPwd = true;
|
||||||
final user = Miscs.pwdRequestWithUserReg.firstMatch(data)?.group(1);
|
final user = Miscs.pwdRequestWithUserReg.firstMatch(data)?.group(1);
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
final pwd = await context.showPwdDialog(user);
|
final pwd = await context.showPwdDialog(user: user, hostId: id);
|
||||||
if (pwd == null || pwd.isEmpty) {
|
if (pwd == null || pwd.isEmpty) {
|
||||||
session.kill(SSHSignal.INT);
|
session.kill(SSHSignal.INT);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class ContainerProvider extends ChangeNotifier {
|
|||||||
ContainerErr? error;
|
ContainerErr? error;
|
||||||
String? runLog;
|
String? runLog;
|
||||||
ContainerType type;
|
ContainerType type;
|
||||||
|
bool sudo = false;
|
||||||
|
|
||||||
ContainerProvider({
|
ContainerProvider({
|
||||||
required this.client,
|
required this.client,
|
||||||
@@ -71,8 +72,7 @@ class ContainerProvider extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> refresh({bool isAuto = false}) async {
|
Future<void> refresh({bool isAuto = false}) async {
|
||||||
final sudo =
|
sudo = await _requiresSudo() && Stores.setting.containerTrySudo.fetch();
|
||||||
await _requiresSudo() && Stores.setting.containerTrySudo.fetch();
|
|
||||||
|
|
||||||
/// If sudo is required and auto refresh is enabled, skip the refresh.
|
/// If sudo is required and auto refresh is enabled, skip the refresh.
|
||||||
/// Or this will ask for pwd again and again.
|
/// Or this will ask for pwd again and again.
|
||||||
@@ -88,6 +88,7 @@ class ContainerProvider extends ChangeNotifier {
|
|||||||
)),
|
)),
|
||||||
context: context,
|
context: context,
|
||||||
onStdout: (data, _) => raw = '$raw$data',
|
onStdout: (data, _) => raw = '$raw$data',
|
||||||
|
id: hostId,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Code 127 means command not found
|
/// Code 127 means command not found
|
||||||
@@ -204,13 +205,14 @@ class ContainerProvider extends ChangeNotifier {
|
|||||||
runLog = '';
|
runLog = '';
|
||||||
final errs = <String>[];
|
final errs = <String>[];
|
||||||
final code = await client?.execWithPwd(
|
final code = await client?.execWithPwd(
|
||||||
_wrap(cmd),
|
_wrap(sudo ? 'sudo -S $cmd' : cmd),
|
||||||
context: context,
|
context: context,
|
||||||
onStdout: (data, _) {
|
onStdout: (data, _) {
|
||||||
runLog = '$runLog$data';
|
runLog = '$runLog$data';
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
},
|
},
|
||||||
onStderr: (data, _) => errs.add(data),
|
onStderr: (data, _) => errs.add(data),
|
||||||
|
id: hostId,
|
||||||
);
|
);
|
||||||
runLog = null;
|
runLog = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|||||||
@@ -255,6 +255,10 @@ class SettingStore extends PersistentStore {
|
|||||||
late final termCursor =
|
late final termCursor =
|
||||||
property('termCursor', TerminalCursorType.block.index);
|
property('termCursor', TerminalCursorType.block.index);
|
||||||
|
|
||||||
|
/// Remerber pwd in memory
|
||||||
|
/// Used for [DialogX.showPwdDialog]
|
||||||
|
late final rememberPwdInMem = property('rememberPwdInMem', true);
|
||||||
|
|
||||||
// Never show these settings for users
|
// Never show these settings for users
|
||||||
//
|
//
|
||||||
// ------BEGIN------
|
// ------BEGIN------
|
||||||
|
|||||||
@@ -193,6 +193,8 @@
|
|||||||
"pwd": "Passwort",
|
"pwd": "Passwort",
|
||||||
"read": "Lesen",
|
"read": "Lesen",
|
||||||
"reboot": "Neustart",
|
"reboot": "Neustart",
|
||||||
|
"rememberPwdInMem": "Passwort im Speicher behalten",
|
||||||
|
"rememberPwdInMemTip": "Für Container, Aufhängen usw.",
|
||||||
"remotePath": "Entfernte Pfade",
|
"remotePath": "Entfernte Pfade",
|
||||||
"rename": "Umbenennen",
|
"rename": "Umbenennen",
|
||||||
"reportBugsOnGithubIssue": "Bitte Bugs auf {url} melden",
|
"reportBugsOnGithubIssue": "Bitte Bugs auf {url} melden",
|
||||||
|
|||||||
@@ -193,6 +193,8 @@
|
|||||||
"pwd": "Password",
|
"pwd": "Password",
|
||||||
"read": "Read",
|
"read": "Read",
|
||||||
"reboot": "Reboot",
|
"reboot": "Reboot",
|
||||||
|
"rememberPwdInMem": "Remember password in memory",
|
||||||
|
"rememberPwdInMemTip": "Used for containers, suspending, etc.",
|
||||||
"remotePath": "Remote path",
|
"remotePath": "Remote path",
|
||||||
"rename": "Rename",
|
"rename": "Rename",
|
||||||
"reportBugsOnGithubIssue": "Please report bugs on {url}",
|
"reportBugsOnGithubIssue": "Please report bugs on {url}",
|
||||||
|
|||||||
@@ -193,6 +193,8 @@
|
|||||||
"pwd": "Contraseña",
|
"pwd": "Contraseña",
|
||||||
"read": "Leer",
|
"read": "Leer",
|
||||||
"reboot": "Reiniciar",
|
"reboot": "Reiniciar",
|
||||||
|
"rememberPwdInMem": "Recordar contraseña en la memoria",
|
||||||
|
"rememberPwdInMemTip": "Utilizado para contenedores, suspensión, etc.",
|
||||||
"remotePath": "Ruta remota",
|
"remotePath": "Ruta remota",
|
||||||
"rename": "Renombrar",
|
"rename": "Renombrar",
|
||||||
"reportBugsOnGithubIssue": "Por favor, informa los problemas en {url}",
|
"reportBugsOnGithubIssue": "Por favor, informa los problemas en {url}",
|
||||||
|
|||||||
@@ -193,6 +193,8 @@
|
|||||||
"pwd": "Mot de passe",
|
"pwd": "Mot de passe",
|
||||||
"read": "Lire",
|
"read": "Lire",
|
||||||
"reboot": "Redémarrer",
|
"reboot": "Redémarrer",
|
||||||
|
"rememberPwdInMem": "Mémoriser le mot de passe en mémoire",
|
||||||
|
"rememberPwdInMemTip": "Utilisé pour les conteneurs, la suspension, etc.",
|
||||||
"remotePath": "Chemin distant",
|
"remotePath": "Chemin distant",
|
||||||
"rename": "Renommer",
|
"rename": "Renommer",
|
||||||
"reportBugsOnGithubIssue": "Veuillez signaler les bogues sur {url}",
|
"reportBugsOnGithubIssue": "Veuillez signaler les bogues sur {url}",
|
||||||
|
|||||||
@@ -193,6 +193,8 @@
|
|||||||
"pwd": "Kata sandi",
|
"pwd": "Kata sandi",
|
||||||
"read": "Baca",
|
"read": "Baca",
|
||||||
"reboot": "Reboot",
|
"reboot": "Reboot",
|
||||||
|
"rememberPwdInMem": "Ingat kata sandi di dalam memori",
|
||||||
|
"rememberPwdInMemTip": "Digunakan untuk kontainer, menangguhkan, dll.",
|
||||||
"remotePath": "Jalur jarak jauh",
|
"remotePath": "Jalur jarak jauh",
|
||||||
"rename": "Ganti nama",
|
"rename": "Ganti nama",
|
||||||
"reportBugsOnGithubIssue": "Harap laporkan bug di {url}",
|
"reportBugsOnGithubIssue": "Harap laporkan bug di {url}",
|
||||||
|
|||||||
@@ -193,6 +193,8 @@
|
|||||||
"pwd": "パスワード",
|
"pwd": "パスワード",
|
||||||
"read": "読み取り",
|
"read": "読み取り",
|
||||||
"reboot": "再起動",
|
"reboot": "再起動",
|
||||||
|
"rememberPwdInMem": "メモリにパスワードを記憶する",
|
||||||
|
"rememberPwdInMemTip": "コンテナ、一時停止などに使用されます。",
|
||||||
"remotePath": "リモートパス",
|
"remotePath": "リモートパス",
|
||||||
"rename": "名前を変更",
|
"rename": "名前を変更",
|
||||||
"reportBugsOnGithubIssue": "{url}で問題を報告してください",
|
"reportBugsOnGithubIssue": "{url}で問題を報告してください",
|
||||||
|
|||||||
@@ -193,6 +193,8 @@
|
|||||||
"pwd": "Senha",
|
"pwd": "Senha",
|
||||||
"read": "Leitura",
|
"read": "Leitura",
|
||||||
"reboot": "Reiniciar",
|
"reboot": "Reiniciar",
|
||||||
|
"rememberPwdInMem": "Lembrar senha na memória",
|
||||||
|
"rememberPwdInMemTip": "Usado para contêineres, suspensão, etc.",
|
||||||
"remotePath": "Caminho remoto",
|
"remotePath": "Caminho remoto",
|
||||||
"rename": "Renomear",
|
"rename": "Renomear",
|
||||||
"reportBugsOnGithubIssue": "Por favor, reporte problemas em {url}",
|
"reportBugsOnGithubIssue": "Por favor, reporte problemas em {url}",
|
||||||
|
|||||||
@@ -193,6 +193,8 @@
|
|||||||
"pwd": "пароль",
|
"pwd": "пароль",
|
||||||
"read": "чтение",
|
"read": "чтение",
|
||||||
"reboot": "перезагрузка",
|
"reboot": "перезагрузка",
|
||||||
|
"rememberPwdInMem": "Запомнить пароль в памяти",
|
||||||
|
"rememberPwdInMemTip": "Используется для контейнеров, приостановки и т. д.",
|
||||||
"remotePath": "удаленный путь",
|
"remotePath": "удаленный путь",
|
||||||
"rename": "переименовать",
|
"rename": "переименовать",
|
||||||
"reportBugsOnGithubIssue": "Пожалуйста, сообщайте о проблемах на {url}",
|
"reportBugsOnGithubIssue": "Пожалуйста, сообщайте о проблемах на {url}",
|
||||||
|
|||||||
@@ -193,6 +193,8 @@
|
|||||||
"pwd": "密码",
|
"pwd": "密码",
|
||||||
"read": "读",
|
"read": "读",
|
||||||
"reboot": "重启",
|
"reboot": "重启",
|
||||||
|
"rememberPwdInMem": "在内存中记住密码",
|
||||||
|
"rememberPwdInMemTip": "用于容器、挂起等",
|
||||||
"remotePath": "远端路径",
|
"remotePath": "远端路径",
|
||||||
"rename": "重命名",
|
"rename": "重命名",
|
||||||
"reportBugsOnGithubIssue": "请到 {url} 提交问题",
|
"reportBugsOnGithubIssue": "请到 {url} 提交问题",
|
||||||
|
|||||||
@@ -193,6 +193,8 @@
|
|||||||
"pwd": "密碼",
|
"pwd": "密碼",
|
||||||
"read": "读",
|
"read": "读",
|
||||||
"reboot": "重启",
|
"reboot": "重启",
|
||||||
|
"rememberPwdInMem": "在記憶體中記住密碼",
|
||||||
|
"rememberPwdInMemTip": "用於容器、暫停等",
|
||||||
"remotePath": "遠端路徑",
|
"remotePath": "遠端路徑",
|
||||||
"rename": "重命名",
|
"rename": "重命名",
|
||||||
"reportBugsOnGithubIssue": "請到 {url} 提交問題",
|
"reportBugsOnGithubIssue": "請到 {url} 提交問題",
|
||||||
|
|||||||
@@ -261,6 +261,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
srv.client?.execWithPwd(
|
srv.client?.execWithPwd(
|
||||||
ShellFunc.suspend.exec,
|
ShellFunc.suspend.exec,
|
||||||
context: context,
|
context: context,
|
||||||
|
id: srv.id,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
typ: l10n.suspend,
|
typ: l10n.suspend,
|
||||||
@@ -274,6 +275,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
func: () => srv.client?.execWithPwd(
|
func: () => srv.client?.execWithPwd(
|
||||||
ShellFunc.shutdown.exec,
|
ShellFunc.shutdown.exec,
|
||||||
context: context,
|
context: context,
|
||||||
|
id: srv.id,
|
||||||
),
|
),
|
||||||
typ: l10n.shutdown,
|
typ: l10n.shutdown,
|
||||||
name: srv.spi.name,
|
name: srv.spi.name,
|
||||||
@@ -286,6 +288,7 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
func: () => srv.client?.execWithPwd(
|
func: () => srv.client?.execWithPwd(
|
||||||
ShellFunc.reboot.exec,
|
ShellFunc.reboot.exec,
|
||||||
context: context,
|
context: context,
|
||||||
|
id: srv.id,
|
||||||
),
|
),
|
||||||
typ: l10n.reboot,
|
typ: l10n.reboot,
|
||||||
name: srv.spi.name,
|
name: srv.spi.name,
|
||||||
|
|||||||
@@ -1048,6 +1048,7 @@ class _SettingPageState extends State<SettingPage> {
|
|||||||
return ExpandTile(
|
return ExpandTile(
|
||||||
title: Text(l10n.more),
|
title: Text(l10n.more),
|
||||||
children: [
|
children: [
|
||||||
|
_buildRememberPwdInMem(),
|
||||||
_buildTextScaler(),
|
_buildTextScaler(),
|
||||||
_buildPreferTemperatureDeviceList(),
|
_buildPreferTemperatureDeviceList(),
|
||||||
_buildKeepStatusWhenErr(),
|
_buildKeepStatusWhenErr(),
|
||||||
@@ -1081,4 +1082,12 @@ class _SettingPageState extends State<SettingPage> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildRememberPwdInMem() {
|
||||||
|
return ListTile(
|
||||||
|
title: Text(l10n.rememberPwdInMem),
|
||||||
|
subtitle: Text(l10n.rememberPwdInMemTip, style: UIs.textGrey),
|
||||||
|
trailing: StoreSwitch(prop: _setting.rememberPwdInMem),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -245,7 +245,11 @@ Future<void> _onPkg(BuildContext context, ServerPrivateInfo spi) async {
|
|||||||
fn: () async {
|
fn: () async {
|
||||||
final updateCmd = pkg.update;
|
final updateCmd = pkg.update;
|
||||||
if (updateCmd != null) {
|
if (updateCmd != null) {
|
||||||
await client.execWithPwd(updateCmd, context: context);
|
await client.execWithPwd(
|
||||||
|
updateCmd,
|
||||||
|
context: context,
|
||||||
|
id: spi.id,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
barrierDismiss: true,
|
barrierDismiss: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user