mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-04 01:24:09 +02:00
more office wip, only wss proxy missing it seems
This commit is contained in:
parent
7910b9d034
commit
2a7f4de2b7
11 changed files with 186 additions and 110 deletions
|
|
@ -78,7 +78,12 @@ impl ServiceTrait for ClamIcap {
|
|||
&["files_antivirus"]
|
||||
}
|
||||
|
||||
async fn post_setup(&self, _docker: &Docker, _cloud_id: &str) -> Result<Vec<String>> {
|
||||
async fn post_setup(
|
||||
&self,
|
||||
_docker: &Docker,
|
||||
_cloud_id: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<Vec<String>> {
|
||||
Ok(vec![
|
||||
"occ config:app:set files_antivirus av_mode --value=icap".into(),
|
||||
"occ config:app:set files_antivirus av_host --value=clamav-icap".into(),
|
||||
|
|
|
|||
|
|
@ -91,7 +91,12 @@ impl ServiceTrait for Kaspersky {
|
|||
&["files_antivirus"]
|
||||
}
|
||||
|
||||
async fn post_setup(&self, _docker: &Docker, _cloud_id: &str) -> Result<Vec<String>> {
|
||||
async fn post_setup(
|
||||
&self,
|
||||
_docker: &Docker,
|
||||
_cloud_id: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<Vec<String>> {
|
||||
Ok(vec![
|
||||
"occ config:app:set files_antivirus av_mode --value=kaspersky".into(),
|
||||
"occ config:app:set files_antivirus av_host --value=kaspersky".into(),
|
||||
|
|
@ -186,7 +191,12 @@ impl ServiceTrait for KasperskyIcap {
|
|||
&["files_antivirus"]
|
||||
}
|
||||
|
||||
async fn post_setup(&self, _docker: &Docker, _cloud_id: &str) -> Result<Vec<String>> {
|
||||
async fn post_setup(
|
||||
&self,
|
||||
_docker: &Docker,
|
||||
_cloud_id: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<Vec<String>> {
|
||||
Ok(vec![
|
||||
"occ config:app:set files_antivirus av_mode --value=icap".into(),
|
||||
"occ config:app:set files_antivirus av_host --value=kaspersky-icap".into(),
|
||||
|
|
|
|||
|
|
@ -26,16 +26,34 @@ impl ServiceTrait for Office {
|
|||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
_config: &HazeConfig,
|
||||
config: &HazeConfig,
|
||||
) -> Result<String> {
|
||||
let image = "collabora/code";
|
||||
pull_image(docker, image).await?;
|
||||
let container_id = self.container_name(cloud_id);
|
||||
let options = Some(CreateContainerOptions {
|
||||
name: self.container_name(cloud_id),
|
||||
name: container_id.clone(),
|
||||
});
|
||||
let mut env = vec!["extra_params=--o:ssl.enable=false --o:ssl.termination=true"];
|
||||
|
||||
let clean_id = container_id.strip_prefix("haze-").unwrap_or(&container_id);
|
||||
let server_name_opt = match (&config.proxy.address, config.proxy.https) {
|
||||
(public, true) if !public.is_empty() => {
|
||||
format!("server_name={clean_id}.{public}")
|
||||
}
|
||||
(public, false) if !public.is_empty() => {
|
||||
format!("server_name={clean_id}.{public}")
|
||||
}
|
||||
_ => "".to_string(),
|
||||
};
|
||||
|
||||
if !server_name_opt.is_empty() {
|
||||
env.push(&server_name_opt);
|
||||
}
|
||||
|
||||
let config = Config {
|
||||
image: Some(image),
|
||||
env: Some(vec!["extra_params=--o:ssl.enable=false"]),
|
||||
env: Some(env),
|
||||
host_config: Some(HostConfig {
|
||||
network_mode: Some(network.to_string()),
|
||||
..Default::default()
|
||||
|
|
@ -74,9 +92,15 @@ impl ServiceTrait for Office {
|
|||
&["richdocuments"]
|
||||
}
|
||||
|
||||
async fn post_setup(&self, docker: &Docker, cloud_id: &str) -> Result<Vec<String>> {
|
||||
async fn post_setup(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
config: &HazeConfig,
|
||||
) -> Result<Vec<String>> {
|
||||
let container = &self.container_name(cloud_id);
|
||||
let info = docker
|
||||
.inspect_container(&self.container_name(cloud_id), None)
|
||||
.inspect_container(container, None)
|
||||
.await
|
||||
.into_diagnostic()?;
|
||||
let ip = if matches!(
|
||||
|
|
@ -96,6 +120,8 @@ impl ServiceTrait for Office {
|
|||
.ip_address
|
||||
.clone()
|
||||
.unwrap()
|
||||
.parse()
|
||||
.into_diagnostic()?
|
||||
} else {
|
||||
return Err(Report::msg("office not started"));
|
||||
};
|
||||
|
|
@ -105,8 +131,8 @@ impl ServiceTrait for Office {
|
|||
ip
|
||||
),
|
||||
format!(
|
||||
r#"occ config:app:set richdocuments public_wopi_url --value="http://{}:9980""#,
|
||||
ip
|
||||
r#"occ config:app:set richdocuments public_wopi_url --value="{}""#,
|
||||
config.proxy.addr_with_port(container, ip, 9980)
|
||||
),
|
||||
format!(
|
||||
r#"occ config:app:set richdocuments wopi_root --value="http://{}""#,
|
||||
|
|
|
|||
|
|
@ -73,7 +73,12 @@ impl ServiceTrait for OnlyOffice {
|
|||
&["onlyoffice"]
|
||||
}
|
||||
|
||||
async fn post_setup(&self, docker: &Docker, cloud_id: &str) -> Result<Vec<String>> {
|
||||
async fn post_setup(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<Vec<String>> {
|
||||
let info = docker
|
||||
.inspect_container(&self.container_name(cloud_id), None)
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -2,13 +2,10 @@ use crate::config::HazeConfig;
|
|||
use crate::image::pull_image;
|
||||
use crate::service::ServiceTrait;
|
||||
use bollard::container::{Config, CreateContainerOptions, NetworkingConfig};
|
||||
use bollard::models::{ContainerState, EndpointSettings, HostConfig};
|
||||
use bollard::models::{EndpointSettings, HostConfig};
|
||||
use bollard::Docker;
|
||||
use maplit::hashmap;
|
||||
use miette::{IntoDiagnostic, Report, Result, WrapErr};
|
||||
use std::net::IpAddr;
|
||||
use std::time::Duration;
|
||||
use tokio::time::{sleep, timeout};
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct NotifyPush;
|
||||
|
|
@ -85,7 +82,12 @@ impl ServiceTrait for NotifyPush {
|
|||
Ok(true)
|
||||
}
|
||||
|
||||
async fn post_setup(&self, docker: &Docker, cloud_id: &str) -> Result<Vec<String>> {
|
||||
async fn post_setup(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<Vec<String>> {
|
||||
let ip = self.get_ip(docker, cloud_id).await?;
|
||||
Ok(vec![
|
||||
format!("occ config:system:set trusted_proxies 1 --value {}", ip),
|
||||
|
|
@ -93,69 +95,3 @@ impl ServiceTrait for NotifyPush {
|
|||
])
|
||||
}
|
||||
}
|
||||
|
||||
impl NotifyPush {
|
||||
async fn is_push_running(&self, docker: &Docker, cloud_id: &str) -> Result<bool> {
|
||||
let info = docker
|
||||
.inspect_container(&self.container_name(cloud_id), None)
|
||||
.await
|
||||
.into_diagnostic()?;
|
||||
Ok(matches!(
|
||||
info.state,
|
||||
Some(ContainerState {
|
||||
running: Some(true),
|
||||
..
|
||||
})
|
||||
))
|
||||
}
|
||||
|
||||
async fn wait_for_push(&self, docker: &Docker, cloud_id: &str) -> Result<()> {
|
||||
timeout(Duration::from_secs(30), async {
|
||||
while !self.is_push_running(docker, cloud_id).await? {
|
||||
sleep(Duration::from_millis(100)).await
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
.into_diagnostic()
|
||||
.wrap_err("Timeout after 30 seconds")?
|
||||
}
|
||||
|
||||
pub async fn get_ip(&self, docker: &Docker, cloud_id: &str) -> Result<IpAddr> {
|
||||
docker
|
||||
.start_container::<String>(&self.container_name(cloud_id), None)
|
||||
.await
|
||||
.into_diagnostic()?;
|
||||
self.wait_for_push(docker, cloud_id).await?;
|
||||
|
||||
sleep(Duration::from_millis(100)).await;
|
||||
|
||||
let info = docker
|
||||
.inspect_container(&self.container_name(cloud_id), None)
|
||||
.await
|
||||
.into_diagnostic()?;
|
||||
if matches!(
|
||||
info.state,
|
||||
Some(ContainerState {
|
||||
running: Some(true),
|
||||
..
|
||||
})
|
||||
) {
|
||||
info.network_settings
|
||||
.unwrap()
|
||||
.networks
|
||||
.unwrap()
|
||||
.values()
|
||||
.next()
|
||||
.unwrap()
|
||||
.ip_address
|
||||
.clone()
|
||||
.unwrap()
|
||||
.parse()
|
||||
.into_diagnostic()
|
||||
.wrap_err("Invalid ip address")
|
||||
} else {
|
||||
Err(Report::msg("notify_push not started"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,12 @@ impl ServiceTrait for Smb {
|
|||
Ok(true)
|
||||
}
|
||||
|
||||
async fn post_setup(&self, _docker: &Docker, _cloud_id: &str) -> Result<Vec<String>> {
|
||||
async fn post_setup(
|
||||
&self,
|
||||
_docker: &Docker,
|
||||
_cloud_id: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<Vec<String>> {
|
||||
Ok(vec![
|
||||
"occ files_external:create smb smb password::password".into(),
|
||||
"occ files_external:config 1 host smb".into(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue