Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read DNS ip address from openvpn output ( fix #3 ) #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ documentation = "https://docs.rs/openaws-vpn-client/"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
regex= "1"
gtk = "=0.14.3"
lazy_static = "=1.4.0"
tokio = { version = "=1.14.0", features = ["full"] }
Expand Down
5 changes: 5 additions & 0 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ pub async fn connect_ovpn(
if let Ok(ref line) = next {
if let Some(line) = line {
log.append_process(pid, line.as_str());
tokio::spawn(async move {
// Process each socket concurrently.
parse_dns(line.to_string())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

68% of developers fix this issue

compiler-message: error[E0425]: cannot find function parse_dns in this scope
--> src/cmd.rs:170:21
|
170 | parse_dns(line.to_string())
| ^^^^^^^^^ not found in this scope
|
help: consider importing this function
|
1 | use crate::dns::parse_dns;
|


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

.and_then(|dns_address| _WIP_("Do something with this IP address"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

68% of developers fix this issue

compiler-message: error[E0425]: cannot find function _WIP_ in this scope
--> src/cmd.rs:171:49
|
171 | .and_then(|dns_address| WIP("Do something with this IP address"))
| ^^^^^ not found in this scope


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Help us improve LIFT! (Sonatype LiftBot external survey)

Was this a good recommendation for you? Answering this survey will not impact your Lift settings.

[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is intentional: I don't know what "interface index" to give to systemd-resolved

});
} else {
break;
}
Expand Down
21 changes: 21 additions & 0 deletions src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use domain::base::iana::Class;
use domain::base::{Dname, Rtype};
use domain::rdata::A;
use rand::prelude::*;
use regex::Regex;
use std::net::IpAddr;
use std::ops::Deref;
use std::rc::Rc;
Expand Down Expand Up @@ -78,3 +79,23 @@ fn rng_domain() -> String {
rng.fill_bytes(&mut bts);
hex::encode(bts)
}

/// parse DNS from openvpn log written to stdout
pub fn parse_dns(line: String) -> Option<String> {
let header = &line.as_bytes()[..32];
// expect a header for this line
if std::str::from_utf8(header).unwrap() != "PUSH: Received control message: ".to_string() {
println!(
"no son iguales «{}» & »{}«",
std::str::from_utf8(header).unwrap(),
"PUSH: Received control message:"
);
return None;
}
let dhcp_option_dns_re = Regex::new(r"dhcp-option DNS ([^,]+),").unwrap();
for ip in dhcp_option_dns_re.captures_iter(&line) {
return Some((&ip[1]).to_string());
}
None
}