Made LE token configurable and using lowercase TXT search
This commit is contained in:
parent
ee608ad0c8
commit
a90a265d8e
@ -30,6 +30,7 @@ std::vector<sockaddr_storage> bindings(uint16_t port) {
|
||||
return result;
|
||||
}
|
||||
|
||||
extern std::string le_token;
|
||||
int main(int argc, char** argv) {
|
||||
evthread_use_pthreads();
|
||||
|
||||
@ -66,6 +67,9 @@ int main(int argc, char** argv) {
|
||||
if(line == "end" || line == "stop") {
|
||||
std::cout << "Stopping server\n";
|
||||
break;
|
||||
} else if(line.length() > 13 && line.substr(0, 13) == "set-le-token ") {
|
||||
le_token = line.substr(13);
|
||||
std::cout << "Setting letsencrypt token to: " << le_token << "\n";
|
||||
} else {
|
||||
std::cerr << "Unknown command \"" << line << "\"\n";
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "./server.h"
|
||||
#include "./net.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <teadns/parser.h>
|
||||
#include <teadns/builder.h>
|
||||
@ -9,6 +10,7 @@
|
||||
using namespace ts::dns;
|
||||
using namespace ts::dns::builder;
|
||||
|
||||
std::string le_token;
|
||||
void WebDNSHandler::handle_message(const std::shared_ptr<DNSServerBinding>& binding, const sockaddr_storage &address, void *buffer, size_t size) {
|
||||
std::cout << "Received DNS request from " << net::to_string(address) << ":\n";
|
||||
DNSParser parser{0, nullptr, buffer, size};
|
||||
@ -71,6 +73,8 @@ void WebDNSHandler::handle_message(const std::shared_ptr<DNSServerBinding>& bind
|
||||
a.builder<rrbuilder::A>().set_address(resp);
|
||||
} else if(query->qclass() == rrclass::IN && query->qtype() == rrtype::TXT) {
|
||||
auto dn = query->qname();
|
||||
std::transform(dn.begin(), dn.end(), dn.begin(), tolower);
|
||||
|
||||
if(dn == "_acme-challenge.con-gate.work") {
|
||||
std::cout << " Letsencrypt request\n";
|
||||
std::cout << " Sending predefined key\n";
|
||||
@ -79,7 +83,7 @@ void WebDNSHandler::handle_message(const std::shared_ptr<DNSServerBinding>& bind
|
||||
a.set_class(query->qclass());
|
||||
a.set_type(query->qtype());
|
||||
a.set_ttl(120);
|
||||
a.builder<rrbuilder::TXT>().set_text("-YEqeIGJqoOz5uLbUiUfK06--n3jtVoI__6WJY-Ehgk");
|
||||
a.builder<rrbuilder::TXT>().set_text(le_token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user