Working on using trust client
This commit is contained in:
parent
f45632f0b7
commit
24afbe168e
11
Cargo.toml
11
Cargo.toml
|
@ -20,4 +20,13 @@ trust-dns-client = "0.20.2"
|
|||
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "master" }
|
||||
rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket", branch = "master" }
|
||||
serde = "1.0.125"
|
||||
dotenv = "0.15.0"
|
||||
dotenv = "0.15.0"
|
||||
|
||||
|
||||
[[bin]]
|
||||
name = "client"
|
||||
path = "src/client.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "dns"
|
||||
path = "src/main.rs"
|
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
ECHO=$(which echo)
|
||||
NSUPDATE=$(which nsupdate)
|
||||
|
||||
# Set the DNS entry you want to update, please notice the final dot.
|
||||
HOST="test.dyn.commoninternet.net"
|
||||
|
||||
# Set the key provided by your DNS administrator
|
||||
KEY="/etc/named/Kmydomain.com.+157+19553.key"
|
||||
|
||||
# Set the DNS server name or IP
|
||||
#SERVER="dyn.local:12323"
|
||||
SERVER="dyn.local 12323"
|
||||
|
||||
# Set the zone to modify, it can be any zone previous key has permissions to modify
|
||||
ZONE="dyn.commoninternet.net"
|
||||
|
||||
# Get your public IP address in the quickest and fanciest
|
||||
# way to if you have bind-tools installed
|
||||
#IP=`dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'`
|
||||
#OLDIP=`dig $HOST +short @8.8.8.8`
|
||||
IP="1.1.1.9"
|
||||
OLDIP="0.0.0.0"
|
||||
|
||||
if [ "$IP" != "$OLDIP" ];
|
||||
then
|
||||
$ECHO "server $SERVER" > /tmp/nsupdate
|
||||
$ECHO "debug yes" >> /tmp/nsupdate
|
||||
$ECHO "zone $ZONE" >> /tmp/nsupdate
|
||||
# $ECHO "update delete $HOST" >> /tmp/nsupdate
|
||||
$ECHO "update add $HOST 600 A $IP" >> /tmp/nsupdate
|
||||
$ECHO "send" >> /tmp/nsupdate
|
||||
else
|
||||
$ECHO "No update needed, exiting..."
|
||||
fi
|
||||
$NSUPDATE -k ${KEY} -v /tmp/nsupdate
|
|
@ -0,0 +1,47 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
use futures::try_join;
|
||||
use std::io;
|
||||
use tokio::task;
|
||||
|
||||
|
||||
use std::net::Ipv4Addr;
|
||||
use std::str::FromStr;
|
||||
use trust_dns_client::client::{Client, SyncClient};
|
||||
use trust_dns_client::udp::UdpClientConnection;
|
||||
use trust_dns_client::op::DnsResponse;
|
||||
use trust_dns_client::rr::{DNSClass, Name, RData, Record, RecordType};
|
||||
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
||||
let address = "dyn.local:12323".parse().unwrap();
|
||||
let conn = UdpClientConnection::new(address).unwrap();
|
||||
let client = SyncClient::new(conn);
|
||||
|
||||
// Specify the name, note the final '.' which specifies it's an FQDN
|
||||
let name = Name::from_str("www.example.com.").unwrap();
|
||||
|
||||
// NOTE: see 'Setup a connection' example above
|
||||
// Send the query and get a message response, see RecordType for all supported options
|
||||
let response: DnsResponse = client.query(&name, DNSClass::IN, RecordType::A).unwrap();
|
||||
|
||||
// Messages are the packets sent between client and server in DNS, DnsResonse's can be
|
||||
// dereferenced to a Message. There are many fields to a Message, It's beyond the scope
|
||||
// of these examples to explain them. See trust_dns::op::message::Message for more details.
|
||||
// generally we will be interested in the Message::answers
|
||||
let answers: &[Record] = response.answers();
|
||||
|
||||
// Records are generic objects which can contain any data.
|
||||
// In order to access it we need to first check what type of record it is
|
||||
// In this case we are interested in A, IPv4 address
|
||||
if let &RData::A(ref ip) = answers[0].rdata() {
|
||||
assert_eq!(*ip, Ipv4Addr::new(93, 184, 216, 34))
|
||||
} else {
|
||||
assert!(false, "unexpected result")
|
||||
}
|
||||
}
|
11
src/dns.rs
11
src/dns.rs
|
@ -56,12 +56,13 @@ impl DnsManager {
|
|||
authority_records
|
||||
}
|
||||
|
||||
fn upsert_domain(mut authority: InMemoryAuthority, domain: String, ip: Ipv4Addr) {
|
||||
fn upsert_domain(mut authority: InMemoryAuthority, domain: String, ip: Ipv4Addr) -> InMemoryAuthority {
|
||||
let dyn_name = Name::from_str(&domain).unwrap();
|
||||
let dyn_ttl = 60;
|
||||
let dyn_rdata = RData::A(ip);
|
||||
let dyn_record = Record::from_rdata(dyn_name, dyn_ttl, dyn_rdata);
|
||||
authority.upsert(dyn_record, authority.serial());
|
||||
authority
|
||||
}
|
||||
|
||||
fn build_catalog(&mut self) {
|
||||
|
@ -72,7 +73,7 @@ impl DnsManager {
|
|||
let authority_allow_axfr = false;
|
||||
|
||||
// first create an authority for root_dyn_zone
|
||||
let authority = InMemoryAuthority::new(
|
||||
let mut authority = InMemoryAuthority::new(
|
||||
authority_name.clone(),
|
||||
authority_records,
|
||||
authority_zone_type,
|
||||
|
@ -83,7 +84,11 @@ impl DnsManager {
|
|||
// then upsert records into the authority for all records in database
|
||||
let domain1 = format!("test.{}", self.dyn_root_zone);
|
||||
let ip1 = Ipv4Addr::new(1, 1, 1, 1);
|
||||
DnsManager::upsert_domain(authority, domain1, ip1);
|
||||
authority = DnsManager::upsert_domain(authority, domain1, ip1);
|
||||
|
||||
let domain2 = format!("peach.{}", self.dyn_root_zone);
|
||||
let ip2 = Ipv4Addr::new(1, 1, 1, 3);
|
||||
authority = DnsManager::upsert_domain(authority, domain2, ip2);
|
||||
|
||||
// finally put the authority into the catalog
|
||||
self.catalog.upsert(
|
||||
|
|
Loading…
Reference in New Issue