Skip to content

Commit ddef0b8

Browse files
committed
implement tcp proxy and improve command running
1 parent 8aaa293 commit ddef0b8

10 files changed

Lines changed: 1780 additions & 60 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = "2024"
77
server = [
88
"axum",
99
"base32",
10-
"futures",
1110
"hex",
1211
"libc",
1312
"log",
@@ -31,7 +30,6 @@ daemon = [
3130
"sdnotify",
3231
"tempfile",
3332
"tokio-tasks",
34-
"futures",
3533
]
3634
nix = ["dep:nix"]
3735

@@ -52,7 +50,7 @@ cgroups-rs = {version = "0.2", optional=true}
5250
chrono = {version = "0.4", default-features = false, features = ["std", "clock"], optional=true}
5351
clap = {version = "4", default-features = false, features=['std', 'derive', 'help', 'suggestions', 'usage', 'color']}
5452
dirs = "6"
55-
futures = {version = "0.3", optional = true}
53+
futures = {version = "0.3" }
5654
futures-util = "0.3"
5755
hex = {version = "0.4", optional = true}
5856
http-body-util = "0.1"

src/action_types.rs

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,94 @@ pub struct IRunCommandFinished {
10941094
pub status: i32,
10951095
}
10961096

1097+
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
1098+
pub struct ISocketConnect {
1099+
pub msg_id: u64,
1100+
pub socket_id: u64,
1101+
pub host: String,
1102+
pub dst: String,
1103+
}
1104+
1105+
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
1106+
pub struct IResponse {
1107+
pub msg_id: u64,
1108+
#[serde(skip_serializing_if = "Option::is_none")]
1109+
pub error: Option<String>,
1110+
}
1111+
1112+
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
1113+
pub struct ISocketClose {
1114+
pub msg_id: u64,
1115+
pub socket_id: u64,
1116+
}
1117+
1118+
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
1119+
pub struct ISocketSend {
1120+
pub msg_id: u64,
1121+
pub socket_id: u64,
1122+
// Base 64 encoded binary data to send on port, if non close the write part of the socket
1123+
pub data: Option<String>,
1124+
}
1125+
1126+
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
1127+
pub struct ISocketRecv {
1128+
pub socket_id: u64,
1129+
// Base 64 encoded binary data read, if none no more data will be sent
1130+
pub data: Option<String>,
1131+
}
1132+
1133+
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
1134+
pub struct ICommandSpawn {
1135+
pub msg_id: u64,
1136+
pub command_id: u64,
1137+
pub host: String,
1138+
pub program: String,
1139+
pub args: Vec<String>,
1140+
pub forward_stdin: bool,
1141+
pub forward_stdout: bool,
1142+
pub forward_stderr: bool,
1143+
#[serde(skip_serializing_if = "Option::is_none")]
1144+
pub env: Option<HashMap<String, String>>,
1145+
#[serde(skip_serializing_if = "Option::is_none")]
1146+
pub cwd: Option<String>,
1147+
}
1148+
1149+
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
1150+
pub struct ICommandStdin {
1151+
pub msg_id: u64,
1152+
pub command_id: u64,
1153+
// Base64 encode binary data for fd, if none close fd
1154+
pub data: Option<String>,
1155+
}
1156+
1157+
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
1158+
pub struct ICommandSignal {
1159+
pub msg_id: u64,
1160+
pub command_id: u64,
1161+
pub signal: i32,
1162+
}
1163+
1164+
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
1165+
pub struct ICommandStdout {
1166+
pub command_id: u64,
1167+
// Base64 encode binary data from fd, if none fd is closed
1168+
pub data: Option<String>,
1169+
}
1170+
1171+
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
1172+
pub struct ICommandStderr {
1173+
pub command_id: u64,
1174+
// Base64 encode binary data from fd, if none fd is closed
1175+
pub data: Option<String>,
1176+
}
1177+
1178+
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
1179+
pub struct ICommandFinished {
1180+
pub command_id: u64,
1181+
pub code: i32,
1182+
pub signal: Option<i32>,
1183+
}
1184+
10971185
#[derive(Serialize, Deserialize, Clone, Debug, TS)]
10981186
#[serde(tag = "type", rename_all = "PascalCase")]
10991187
pub enum IServerAction {
@@ -1131,6 +1219,11 @@ pub enum IServerAction {
11311219
SetPage(ISetPageAction),
11321220
ToggleDeploymentObject(IToggleDeploymentObject),
11331221
GetSecretRes(IGetSecretRes),
1222+
Response(IResponse),
1223+
SocketRecv(ISocketRecv),
1224+
CommandStdout(ICommandStdout),
1225+
CommandStderr(ICommandStderr),
1226+
CommandFinished(ICommandFinished),
11341227
}
11351228

11361229
impl IServerAction {
@@ -1170,6 +1263,11 @@ impl IServerAction {
11701263
IServerAction::SetMessagesDismissed(_) => "SetMessagesDismissed",
11711264
IServerAction::SetPage(_) => "SetPage",
11721265
IServerAction::ToggleDeploymentObject(_) => "ToggleDeploymentObject",
1266+
IServerAction::Response(_) => "Response",
1267+
IServerAction::SocketRecv(_) => "SocketRecv",
1268+
IServerAction::CommandStdout(_) => "CommandStdout",
1269+
IServerAction::CommandStderr(_) => "CommandStderr",
1270+
IServerAction::CommandFinished(_) => "CommandFinished",
11731271
}
11741272
}
11751273
}
@@ -1214,6 +1312,12 @@ pub enum IClientAction {
12141312
StopDeployment(IStopDeployment),
12151313
ToggleDeploymentObject(IToggleDeploymentObject),
12161314
GetSecret(IGetSecret),
1315+
SocketConnect(ISocketConnect),
1316+
SocketClose(ISocketClose),
1317+
SocketSend(ISocketSend),
1318+
CommandSpawn(ICommandSpawn),
1319+
CommandStdin(ICommandStdin),
1320+
CommandSignal(ICommandSignal),
12171321
}
12181322

12191323
impl IClientAction {
@@ -1256,6 +1360,60 @@ impl IClientAction {
12561360
IClientAction::ToggleDeploymentObject(_) => "ToggleDeploymentObject",
12571361
IClientAction::MarkDeployed(_) => "MarkDeployed",
12581362
IClientAction::GetSecret(_) => "GetSecret",
1363+
IClientAction::SocketConnect(_) => "SocketConnect",
1364+
IClientAction::SocketClose(_) => "SocketClose",
1365+
IClientAction::SocketSend(_) => "SocketSend",
1366+
IClientAction::CommandSpawn(_) => "CommandSpawn",
1367+
IClientAction::CommandStdin(_) => "CommandStdin",
1368+
IClientAction::CommandSignal(_) => "CommandSignal",
1369+
}
1370+
}
1371+
1372+
pub fn msg_id(&self) -> Option<u64> {
1373+
match self {
1374+
IClientAction::CancelDeployment(_) => None,
1375+
IClientAction::Debug(_) => None,
1376+
IClientAction::DeleteObject(_) => None,
1377+
IClientAction::DeployObject(_) => None,
1378+
IClientAction::MarkDeployed(_) => None,
1379+
IClientAction::DockerContainerForget(_) => None,
1380+
IClientAction::DockerImageSetPin(_) => None,
1381+
IClientAction::DockerImageTagSetPin(_) => None,
1382+
IClientAction::DockerListDeploymentHistory(_) => None,
1383+
IClientAction::DockerListDeployments(_) => None,
1384+
IClientAction::DockerListImageByHash(_) => None,
1385+
IClientAction::DockerListImageTagHistory(_) => None,
1386+
IClientAction::DockerListImageTags(_) => None,
1387+
IClientAction::FetchObject(_) => None,
1388+
IClientAction::GenerateKey(_) => None,
1389+
IClientAction::GetObjectHistory(_) => None,
1390+
IClientAction::GetObjectId(_) => None,
1391+
IClientAction::Login(_) => None,
1392+
IClientAction::Logout(_) => None,
1393+
IClientAction::MessageTextReq(_) => None,
1394+
IClientAction::ModifiedFilesList(_) => None,
1395+
IClientAction::ModifiedFilesResolve(_) => None,
1396+
IClientAction::ModifiedFilesScan(_) => None,
1397+
IClientAction::RequestAuthStatus(_) => None,
1398+
IClientAction::RequestInitialState(_) => None,
1399+
IClientAction::ResetServerState(_) => None,
1400+
IClientAction::RunCommand(_) => None,
1401+
IClientAction::RunCommandTerminate(_) => None,
1402+
IClientAction::SaveObject(_) => None,
1403+
IClientAction::Search(_) => None,
1404+
IClientAction::ServiceDeployStart(_) => None,
1405+
IClientAction::ServiceRedeployStart(_) => None,
1406+
IClientAction::SetMessageDismissed(_) => None,
1407+
IClientAction::StartDeployment(_) => None,
1408+
IClientAction::StopDeployment(_) => None,
1409+
IClientAction::ToggleDeploymentObject(_) => None,
1410+
IClientAction::SocketConnect(act) => Some(act.msg_id),
1411+
IClientAction::SocketClose(act) => Some(act.msg_id),
1412+
IClientAction::SocketSend(act) => Some(act.msg_id),
1413+
IClientAction::CommandSpawn(act) => Some(act.msg_id),
1414+
IClientAction::CommandStdin(act) => Some(act.msg_id),
1415+
IClientAction::CommandSignal(act) => Some(act.msg_id),
1416+
IClientAction::GetSecret(_) => None,
12591417
}
12601418
}
12611419
}
@@ -1361,6 +1519,17 @@ pub fn export_ts() -> Vec<String> {
13611519
IGetObjectIdRes::export_to_string().unwrap(),
13621520
IServerAction::export_to_string().unwrap(),
13631521
IClientAction::export_to_string().unwrap(),
1522+
IResponse::export_to_string().unwrap(),
1523+
ISocketConnect::export_to_string().unwrap(),
1524+
ISocketClose::export_to_string().unwrap(),
1525+
ISocketSend::export_to_string().unwrap(),
1526+
ICommandSpawn::export_to_string().unwrap(),
1527+
ICommandStdin::export_to_string().unwrap(),
1528+
ICommandSignal::export_to_string().unwrap(),
1529+
ISocketRecv::export_to_string().unwrap(),
1530+
ICommandStdout::export_to_string().unwrap(),
1531+
ICommandStderr::export_to_string().unwrap(),
1532+
ICommandFinished::export_to_string().unwrap(),
13641533
]
13651534
}
13661535

0 commit comments

Comments
 (0)