@@ -6,7 +6,6 @@ use tracing::info;
66use serde_xml_rs:: from_str;
77
88const PLESK_API_PATH : & str = "/enterprise/control/agent.php" ;
9- const ACME_CHALLENGE_PREFIX : & str = "_acme-challenge" ;
109
1110#[ derive( Clone ) ]
1211pub struct PleskAPI {
@@ -82,7 +81,7 @@ impl PleskAPI {
8281 . header ( "HTTP_AUTH_PASSWD" , self . password . clone ( ) )
8382 }
8483
85- pub async fn add_challenge ( & self , challenge_string : String ) -> Result < String , Error > {
84+ pub async fn add_challenge ( & self , host : String , challenge_string : String ) -> Result < String , Error > {
8685 let payload = format ! (
8786 r#"
8887 <packet>
@@ -97,7 +96,7 @@ impl PleskAPI {
9796 </packet>
9897 "# ,
9998 self . site_id,
100- ACME_CHALLENGE_PREFIX ,
99+ host ,
101100 challenge_string
102101 ) ;
103102 let response = self
@@ -120,7 +119,7 @@ impl PleskAPI {
120119 let error_msg = dns_resp_record. result . errtext . unwrap ( ) ;
121120 if error_msg. contains ( "exists" ) {
122121 info ! ( "Record already exists, retrieving record ID" ) ;
123- let record_id = self . get_challenge_record_id ( ) . await ?;
122+ let record_id = self . get_challenge_record_id ( host ) . await ?;
124123 return Ok ( record_id) ;
125124 } else {
126125 let error = io:: Error :: new (
@@ -195,7 +194,7 @@ impl PleskAPI {
195194 Err ( anyhow ! ( error) )
196195 }
197196
198- pub async fn get_challenge_record_id ( & self ) -> Result < String , Error > {
197+ pub async fn get_challenge_record_id ( & self , host : & String ) -> Result < String , Error > {
199198 info ! ( "Getting challenge record ID" ) ;
200199 let response = self
201200 . create_request ( )
@@ -232,7 +231,7 @@ impl PleskAPI {
232231 continue ;
233232 }
234233 let record_data = action. data . unwrap ( ) ;
235- if record_data. host . contains ( ACME_CHALLENGE_PREFIX ) {
234+ if record_data. host . contains ( host ) && record_data . record_type == "TXT" {
236235 info ! ( "Found record ID: {}" , action. id. clone( ) . unwrap( ) ) ;
237236 return Ok ( action. id . unwrap ( ) ) ;
238237 }
0 commit comments