Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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,556 changes: 843 additions & 713 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
name = "certbot-alfahosting"
version = "1.0.2"
authors = ["Lukas Wagner <appdev.lukaswagner@gmail.com>"]
edition = "2018"
edition = "2021"
build="cargo-scripts/build.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.7.2"
native-tls = "0.2.3"
rand = "0.8.5"
native-tls = "0.2.10"
imap = "1.0.2"
regex = "1.3.1"
headless_chrome = "0.9.0"
acme-lib = "0.5.2"
toml = "0.5.5"
serde = "1.0.104"
regex = "1.6.0"
headless_chrome = "1.0.5"
acme-lib = "0.8.2"
toml = "0.7.2"
serde = "1.0.144"
15 changes: 7 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
FROM centos:centos8
# FROM ubuntu:18.04
FROM ubuntu:jammy

RUN mkdir /etc/letsencrypt
RUN mkdir /etc/certbot-alfahosting

RUN dnf install -y wget
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
RUN dnf install -y ./google-chrome-stable_current_x86_64.rpm
RUN rm ./google-chrome-stable_current_x86_64.rpm
RUN apt-get update && apt-get upgrade -y

# RUN apt-get -y update && apt-get -y install chromium-browser
RUN apt-get install -y wget
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
RUN rm ./google-chrome-stable_current_amd64.deb

COPY target/x86_64-unknown-linux-gnu/release/certbot-alfahosting /usr/bin/certbot-alfahosting

VOLUME [ "/etc/letsencrypt", "/etc/certbot-alfahosting" ]

CMD [ "/usr/bin/certbot-alfahosting" ]
CMD [ "/usr/bin/certbot-alfahosting" ]
2 changes: 1 addition & 1 deletion scripts/build-prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR="$( cd "$(dirname "$0")"/.. ; pwd -P )"

docker run --name build_certbot-alfahosting \
-v "$WORKDIR:/root/src" \
--rm -i -t -w=/root/src rust:1-stretch \
--rm -i -t -w=/root/src rust:1-buster \
cargo build --release --target=x86_64-unknown-linux-gnu

docker build -t certbot-alfahosting "$WORKDIR"
42 changes: 28 additions & 14 deletions src/browse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ pub fn browse_alfahosting_signin(tab: &Arc<Tab>, config: &AlfahostingConfig) {
tab.navigate_to("https://alfahosting.de/kunden-login/")
.unwrap();
tab.wait_until_navigated().unwrap();
std::thread::sleep(std::time::Duration::from_millis(2000));
let accept_cookie_button = tab
.find_element("[data-cookiefirst-button=\"primary\"]")
.find_element("#cmpbntyestxt")
.unwrap();
accept_cookie_button.click().unwrap();
std::thread::sleep(std::time::Duration::from_millis(
Expand All @@ -22,6 +23,9 @@ pub fn browse_alfahosting_signin(tab: &Arc<Tab>, config: &AlfahostingConfig) {
let submit_button = tab
.find_element("#loginForm input[type=\"submit\"]")
.unwrap();
// close possible ad popup
tab.press_key("Escape").unwrap();
std::thread::sleep(std::time::Duration::from_millis(500));
tab.press_key("PageDown").unwrap();
std::thread::sleep(std::time::Duration::from_millis(500));
form_login.scroll_into_view().unwrap();
Expand Down Expand Up @@ -83,7 +87,17 @@ pub fn browse_alfahosting_dns(tab: &Arc<Tab>, config: &AlfahostingConfig) {
2_000 + (rand::random::<u64>() % 3_000),
));
tab.navigate_to(
"https://secure.alfahosting.de/kunden/index.php/Kundencenter:Tarife/Details#dns",
"https://secure.alfahosting.de/kunden/index.php/Kundencenter:Tarife/Details#settings_index",
)
.unwrap();
std::thread::sleep(std::time::Duration::from_millis(
2_000 + (rand::random::<u64>() % 3_000),
));
let body = tab.find_element("body").unwrap();
body.call_js_fn(
"function () {document.fire('settings_index:reload', {page:'dns'});return false;}",
vec![],
false,
)
.unwrap();
std::thread::sleep(std::time::Duration::from_millis(
Expand All @@ -110,6 +124,7 @@ pub fn browse_alfahosting_domain_create_acme(
id
)
.as_str(),
vec![],
false,
)
.unwrap();
Expand All @@ -126,6 +141,7 @@ pub fn browse_alfahosting_domain_create_acme(
));
body.call_js_fn(
"function () {document.fire('dns:exec_zonelist_add');return false;}",
vec![],
false,
)
.unwrap();
Expand All @@ -137,20 +153,15 @@ pub fn browse_alfahosting_domain_create_acme(
pub fn browse_alfahosting_domain_delete_last_dns_entry(tab: &Arc<Tab>, id: String) {
dns_open_domain_and_scroll_into_view(tab, &id);
overwrite_window_popups(tab);
let last_entry_id = tab
let entries = tab
.find_elements(format!("#dns_entries_{} .dns_entry", id).as_str())
.unwrap()
.unwrap();
let last_entry = entries
.iter()
.fold(String::new(), |current, elem| {
if let Some(attributes) = elem.get_attributes().unwrap() {
if let Some(new_id) = attributes.get("id") {
return new_id.clone();
}
}
current
});
let button_delete = tab
.find_element(format!("#{} .dns_entry_action", last_entry_id).as_str())
.last()
.unwrap();
let button_delete = last_entry
.find_element(".dns_entry_action")
.unwrap();
button_delete.click().unwrap();
dns_save(tab, &id);
Expand Down Expand Up @@ -184,11 +195,13 @@ fn overwrite_window_popups(tab: &Arc<Tab>) {
let body = tab.find_element("body").unwrap();
body.call_js_fn(
"function () {window.confirm = function myConfirm() {return true;}}",
vec![],
false,
)
.unwrap();
body.call_js_fn(
"function () {window.alert = function myAlert() {return true;}}",
vec![],
false,
)
.unwrap();
Expand All @@ -205,6 +218,7 @@ fn dns_save(tab: &Arc<Tab>, id: &str) {
id
)
.as_str(),
vec![],
false,
)
.unwrap();
Expand Down
6 changes: 3 additions & 3 deletions src/certbot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn request_cert(
+ "/accounts/acme-staging-v02.api.letsencrypt.org/directory";
#[cfg(build = "release")]
let persist_path =
String::from(certpath.0.as_str()) + "/accounts/acme-v01.api.letsencrypt.org/directory";
String::from(certpath.0.as_str()) + "/accounts/acme-v02.api.letsencrypt.org/directory";
create_dir_all(persist_path.as_str()).unwrap();
// Save/load keys and certificates to current dir.
let persist = FilePersist::new(persist_path.as_str());
Expand All @@ -51,8 +51,8 @@ pub fn request_cert(
let ord_new = acc.new_order(primary, &alt)?;

let ord_csr = do_challenges(names, tab, alfahosting_id, ord_new)?;
let (pkey_pri, pkey_pub) = create_p384_key();
let ord_cert = ord_csr.finalize_pkey(pkey_pri, pkey_pub, 5000)?;
let pkey_pri = create_p384_key();
let ord_cert = ord_csr.finalize_pkey(pkey_pri, 5000)?;
let cert = ord_cert.download_and_save_cert()?;

// TODO archive old certs
Expand Down
2 changes: 1 addition & 1 deletion src/imap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn get_code_from_inbox(config: &ImapConfig) -> Result<String, Box<dyn Error>

fn handle_message(message: &imap::types::Fetch) -> Option<String> {
let envelope = message.envelope().unwrap();
if envelope.subject.unwrap() == "=?UTF-8?Q?Alfahosting_-_Anmeldung_von_einem_neuen_Ger=C3=A4t?="
if envelope.subject.unwrap() == "=?UTF8?Q?Alfahosting=20-=20Anm?==?UTF8?Q?eldung?= =?UTF8?Q?=20von=20einem=20neuen=20Ger?==?UTF8?Q?=C3=A4t?="
{
let body = std::str::from_utf8(message.text().unwrap())
.unwrap()
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() {
if let Some(domains) = config.domains {
let browser = configure_browser();
println!("Browser has been configured.");
let tab = browser.wait_for_initial_tab().unwrap();
let tab = browser.new_tab().unwrap();
println!("Successfully opened initial tab.");
browse_alfahosting_signin(&tab, &config.alfahosting);
if browse_alfahosting_check_login_protection(&tab) {
Expand Down Expand Up @@ -100,7 +100,7 @@ fn configure_browser() -> Browser {
lob.port(Some(8467));
match Browser::new(lob.build().unwrap()) {
Ok(browser) => browser,
Err(err) => panic!("{}", err.as_fail()),
Err(err) => panic!("{}", err.to_string()),
}
}

Expand Down