Skip to main content

omnyssh_core/ssh/services/
nginx.rs

1//! Nginx service provider.
2//!
3//! Detects the Nginx web server from probe output.
4
5use async_trait::async_trait;
6
7use super::ServiceProvider;
8use crate::event::ServiceKind;
9use crate::ssh::probe::ProbeOutput;
10
11/// Nginx service provider.
12pub struct NginxProvider;
13
14#[async_trait]
15impl ServiceProvider for NginxProvider {
16    fn kind(&self) -> ServiceKind {
17        ServiceKind::Nginx
18    }
19
20    fn detect(&self, probe_output: &ProbeOutput) -> bool {
21        // Check for nginx in systemd services OR nginx process
22        if let Some(services) = probe_output.get_section("SERVICES") {
23            if services.contains("nginx") {
24                return true;
25            }
26        }
27        if let Some(processes) = probe_output.get_section("PROCESS") {
28            if processes.contains("nginx") {
29                return true;
30            }
31        }
32        false
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn test_nginx_detect_from_process() {
42        let probe = "===OMNYSSH:PROCESS===\nroot 1234 nginx: master process\n";
43        let parsed = ProbeOutput::parse(probe).expect("should parse");
44        assert!(NginxProvider.detect(&parsed));
45    }
46}