mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
new: server tab process
This commit is contained in:
@@ -870,6 +870,12 @@ abstract class S {
|
|||||||
/// **'Private Key'**
|
/// **'Private Key'**
|
||||||
String get privateKey;
|
String get privateKey;
|
||||||
|
|
||||||
|
/// No description provided for @process.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Process'**
|
||||||
|
String get process;
|
||||||
|
|
||||||
/// No description provided for @pushToken.
|
/// No description provided for @pushToken.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
|
|||||||
@@ -413,6 +413,9 @@ class SDe extends S {
|
|||||||
@override
|
@override
|
||||||
String get privateKey => 'Private Key';
|
String get privateKey => 'Private Key';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get process => 'Prozess';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get pushToken => 'Push Token';
|
String get pushToken => 'Push Token';
|
||||||
|
|
||||||
|
|||||||
@@ -413,6 +413,9 @@ class SEn extends S {
|
|||||||
@override
|
@override
|
||||||
String get privateKey => 'Private Key';
|
String get privateKey => 'Private Key';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get process => 'Process';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get pushToken => 'Push token';
|
String get pushToken => 'Push token';
|
||||||
|
|
||||||
|
|||||||
@@ -413,6 +413,9 @@ class SZh extends S {
|
|||||||
@override
|
@override
|
||||||
String get privateKey => '私钥';
|
String get privateKey => '私钥';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get process => '进程';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get pushToken => '消息推送 Token';
|
String get pushToken => '消息推送 Token';
|
||||||
|
|
||||||
@@ -1029,6 +1032,9 @@ class SZhTw extends SZh {
|
|||||||
@override
|
@override
|
||||||
String get privateKey => '私鑰';
|
String get privateKey => '私鑰';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get process => '進程';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get pushToken => '消息推送 Token';
|
String get pushToken => '消息推送 Token';
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ enum ServerTabMenuType {
|
|||||||
snippet,
|
snippet,
|
||||||
pkg,
|
pkg,
|
||||||
docker,
|
docker,
|
||||||
|
process,
|
||||||
edit;
|
edit;
|
||||||
|
|
||||||
IconData get icon {
|
IconData get icon {
|
||||||
@@ -20,6 +21,8 @@ enum ServerTabMenuType {
|
|||||||
return Icons.view_agenda;
|
return Icons.view_agenda;
|
||||||
case ServerTabMenuType.edit:
|
case ServerTabMenuType.edit:
|
||||||
return Icons.edit;
|
return Icons.edit;
|
||||||
|
case ServerTabMenuType.process:
|
||||||
|
return Icons.list_alt_outlined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +38,8 @@ enum ServerTabMenuType {
|
|||||||
return 'Docker';
|
return 'Docker';
|
||||||
case ServerTabMenuType.edit:
|
case ServerTabMenuType.edit:
|
||||||
return s.edit;
|
return s.edit;
|
||||||
|
case ServerTabMenuType.process:
|
||||||
|
return s.process;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
41
lib/data/model/app/shell_func.dart
Normal file
41
lib/data/model/app/shell_func.dart
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
class AppShellFunc {
|
||||||
|
final String name;
|
||||||
|
final String cmd;
|
||||||
|
final String flag;
|
||||||
|
|
||||||
|
const AppShellFunc(this.name, this.cmd, this.flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef AppShellFuncs = List<AppShellFunc>;
|
||||||
|
|
||||||
|
extension AppShellFuncsExt on AppShellFuncs {
|
||||||
|
String get generate {
|
||||||
|
final sb = StringBuffer();
|
||||||
|
// Write each func
|
||||||
|
for (final func in this) {
|
||||||
|
sb.write('''
|
||||||
|
${func.name}() {
|
||||||
|
${func.cmd}
|
||||||
|
}
|
||||||
|
|
||||||
|
''');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write switch case
|
||||||
|
sb.write('case \$1 in\n');
|
||||||
|
for (final func in this) {
|
||||||
|
sb.write('''
|
||||||
|
'-${func.flag}')
|
||||||
|
${func.name}
|
||||||
|
;;
|
||||||
|
''');
|
||||||
|
}
|
||||||
|
sb.write('''
|
||||||
|
*)
|
||||||
|
echo "Invalid argument \$1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
''');
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -240,7 +240,8 @@ class ServerProvider extends BusyProvider {
|
|||||||
|
|
||||||
if (s.client == null) return;
|
if (s.client == null) return;
|
||||||
// run script to get server status
|
// run script to get server status
|
||||||
raw = await s.client!.run("sh $shellPath").string;
|
raw =
|
||||||
|
await s.client!.run("sh $shellPath -${shellFuncStatus.flag}").string;
|
||||||
segments = raw.split(seperator).map((e) => e.trim()).toList();
|
segments = raw.split(seperator).map((e) => e.trim()).toList();
|
||||||
if (raw.isEmpty || segments.length != CmdType.values.length) {
|
if (raw.isEmpty || segments.length != CmdType.values.length) {
|
||||||
s.state = ServerState.failed;
|
s.state = ServerState.failed;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import '../model/app/shell_func.dart';
|
||||||
import 'build_data.dart';
|
import 'build_data.dart';
|
||||||
|
|
||||||
const seperator = 'SrvBox';
|
const seperator = 'SrvBox';
|
||||||
@@ -36,11 +37,37 @@ const _cmdList = [
|
|||||||
'cat /etc/redhat-release',
|
'cat /etc/redhat-release',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
final shellFuncStatus = AppShellFunc(
|
||||||
|
'status',
|
||||||
|
_cmdList.join('\necho $seperator\n'),
|
||||||
|
's',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if `htop` is installed.
|
||||||
|
// Then app open SSH term and use `htop` or `ps` to see process.
|
||||||
|
const shellFuncProcess = AppShellFunc(
|
||||||
|
'process',
|
||||||
|
'''
|
||||||
|
if command -v htop &> /dev/null
|
||||||
|
then
|
||||||
|
htop
|
||||||
|
else
|
||||||
|
top
|
||||||
|
fi
|
||||||
|
''',
|
||||||
|
'p',
|
||||||
|
);
|
||||||
|
|
||||||
|
final _generated = [
|
||||||
|
shellFuncStatus,
|
||||||
|
shellFuncProcess,
|
||||||
|
].generate;
|
||||||
|
|
||||||
final shellCmd = """
|
final shellCmd = """
|
||||||
# Script for app `${BuildData.name} v${BuildData.build}`
|
# Script for app `${BuildData.name} v1.0.${BuildData.build}`
|
||||||
# Delete this file while app is running will cause app crash
|
# Delete this file while app is running will cause app crash
|
||||||
|
|
||||||
${_cmdList.join('\necho $seperator\n')}
|
$_generated
|
||||||
""";
|
""";
|
||||||
|
|
||||||
final installShellCmd = "mkdir -p $serverBoxDir && "
|
final installShellCmd = "mkdir -p $serverBoxDir && "
|
||||||
|
|||||||
@@ -126,6 +126,7 @@
|
|||||||
"port": "Port",
|
"port": "Port",
|
||||||
"preview": "Vorschau",
|
"preview": "Vorschau",
|
||||||
"privateKey": "Private Key",
|
"privateKey": "Private Key",
|
||||||
|
"process": "Prozess",
|
||||||
"pushToken": "Push Token",
|
"pushToken": "Push Token",
|
||||||
"pwd": "Passwort",
|
"pwd": "Passwort",
|
||||||
"remotePath": "Entfernte Pfade",
|
"remotePath": "Entfernte Pfade",
|
||||||
|
|||||||
@@ -129,6 +129,7 @@
|
|||||||
"port": "Port",
|
"port": "Port",
|
||||||
"preview": "Preview",
|
"preview": "Preview",
|
||||||
"privateKey": "Private Key",
|
"privateKey": "Private Key",
|
||||||
|
"process": "Process",
|
||||||
"pushToken": "Push token",
|
"pushToken": "Push token",
|
||||||
"pwd": "Password",
|
"pwd": "Password",
|
||||||
"remotePath": "Remote path",
|
"remotePath": "Remote path",
|
||||||
|
|||||||
@@ -129,6 +129,7 @@
|
|||||||
"port": "端口",
|
"port": "端口",
|
||||||
"preview": "预览",
|
"preview": "预览",
|
||||||
"privateKey": "私钥",
|
"privateKey": "私钥",
|
||||||
|
"process": "进程",
|
||||||
"pushToken": "消息推送 Token",
|
"pushToken": "消息推送 Token",
|
||||||
"pwd": "密码",
|
"pwd": "密码",
|
||||||
"remotePath": "远端路径",
|
"remotePath": "远端路径",
|
||||||
|
|||||||
@@ -126,6 +126,7 @@
|
|||||||
"port": "端口",
|
"port": "端口",
|
||||||
"preview": "預覽",
|
"preview": "預覽",
|
||||||
"privateKey": "私鑰",
|
"privateKey": "私鑰",
|
||||||
|
"process": "進程",
|
||||||
"pushToken": "消息推送 Token",
|
"pushToken": "消息推送 Token",
|
||||||
"pwd": "密碼",
|
"pwd": "密碼",
|
||||||
"remotePath": "遠端路徑",
|
"remotePath": "遠端路徑",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'package:provider/provider.dart';
|
|||||||
import 'package:toolbox/core/extension/navigator.dart';
|
import 'package:toolbox/core/extension/navigator.dart';
|
||||||
import 'package:toolbox/core/extension/order.dart';
|
import 'package:toolbox/core/extension/order.dart';
|
||||||
import 'package:toolbox/core/utils/misc.dart';
|
import 'package:toolbox/core/utils/misc.dart';
|
||||||
|
import 'package:toolbox/data/res/server_cmd.dart';
|
||||||
|
|
||||||
import '../../../core/route.dart';
|
import '../../../core/route.dart';
|
||||||
import '../../../core/utils/ui.dart';
|
import '../../../core/utils/ui.dart';
|
||||||
@@ -336,6 +337,15 @@ class _ServerPageState extends State<ServerPage>
|
|||||||
case ServerTabMenuType.docker:
|
case ServerTabMenuType.docker:
|
||||||
AppRoute(DockerManagePage(spi), 'Docker manage').go(context);
|
AppRoute(DockerManagePage(spi), 'Docker manage').go(context);
|
||||||
break;
|
break;
|
||||||
|
case ServerTabMenuType.process:
|
||||||
|
AppRoute(
|
||||||
|
SSHPage(
|
||||||
|
spi: spi,
|
||||||
|
initCmd: 'sh $shellPath -${shellFuncProcess.flag}',
|
||||||
|
),
|
||||||
|
'ssh page (process)',
|
||||||
|
).go(context);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user