Skip to content

Commit a20574a

Browse files
committed
Added Mailinabox (#18)
1 parent bd1239a commit a20574a

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
require_once __DIR__ . '/BaseProvider.php';
4+
5+
class MailinaboxProvider extends BaseProvider {
6+
public function updateIp(string $ip): bool {
7+
$email = $this->credentials['mabEmail'] ?? null;
8+
$apiKey = $this->credentials['mabApiKey'] ?? null;
9+
$force = !empty($this->credentials['mabForce']) && $this->credentials['mabForce'] == '1';
10+
11+
if (!$email || !$apiKey) {
12+
$this->logger->error("Missing credentials for Mail‑in‑a‑Box DDNS: {$this->domain}");
13+
return false;
14+
}
15+
16+
$url = "https://{$this->credentials['mabHost']}/admin/dns/update";
17+
$postFields = http_build_query([
18+
'force' => $force ? 1 : 0,
19+
]);
20+
21+
$ch = curl_init($url);
22+
curl_setopt_array($ch, [
23+
CURLOPT_RETURNTRANSFER => true,
24+
CURLOPT_USERPWD => "$email:$apiKey",
25+
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
26+
CURLOPT_POST => true,
27+
CURLOPT_POSTFIELDS => $postFields,
28+
CURLOPT_HTTPHEADER => ["Content-Type: application/x-www-form-urlencoded"],
29+
]);
30+
31+
$resp = curl_exec($ch);
32+
if ($resp === false) {
33+
$this->logger->error("Mail‑in‑a‑Box /dns/update request failed: {$this->domain}");
34+
return false;
35+
}
36+
curl_close($ch);
37+
38+
if (strpos($resp, 'updated DNS:') !== false) {
39+
$this->logger->info("Mail‑in‑a‑Box DDNS updated for {$this->domain}: $resp");
40+
return true;
41+
} else {
42+
$this->logger->error("Mail‑in‑a‑Box DDNS update failed for {$this->domain}: $resp");
43+
return false;
44+
}
45+
}
46+
}

src/lib/dyn_dns_update.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
require_once __DIR__ . '/dyn_dns/StratoProvider.php';
88
require_once __DIR__ . '/dyn_dns/NamecheapProvider.php';
99
require_once __DIR__ . '/dyn_dns/CloudflareProvider.php';
10+
require_once __DIR__ . '/dyn_dns/MailinaboxProvider.php';
1011

1112
$domainManager = new PersistentEntityManager(Domain::class, $logger, DB, 'domains');
1213
$domains = $domainManager->list([], ['domain' => 'ASC']);
@@ -33,6 +34,7 @@
3334
'strato' => StratoProvider::class,
3435
'namecheap' => NamecheapProvider::class,
3536
'cloudflare' => CloudflareProvider::class,
37+
'mailinabox' => MailinaboxProvider::class,
3638
default => null,
3739
};
3840

src/public/domains.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@
219219
<option value="strato">Strato</option>
220220
<option value="namecheap">Namecheap</option>
221221
<option value="cloudflare">Cloudflare</option>
222+
<option value="mailinabox">Mailinabox</option>
222223
</select>
223224

224225
<div id="providerFields"></div>
@@ -348,6 +349,12 @@
348349
cloudflare: [
349350
{ label: 'API Token', id: 'cfApiToken', type: 'text' },
350351
{ label: 'Zone ID', id: 'cfZoneId', type: 'text' }
352+
],
353+
mailinabox: [
354+
{ label: 'Host (box.example.com)', id: 'mabHost', type: 'text' },
355+
{ label: 'Email (admin user)', id: 'mabEmail', type: 'text' },
356+
{ label: 'API Key', id: 'mabApiKey', type: 'password' },
357+
{ label: 'Force Update (0 or 1)', id: 'mabForce', type: 'text' }
351358
]
352359
};
353360

0 commit comments

Comments
 (0)