apertodns 1.2.3 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +107 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -173,6 +173,14 @@ const daemonInterval = args.includes("--interval") ? parseInt(args[args.indexOf(
173
173
  const showMyIp = args.includes("--my-ip") || args.includes("--ip");
174
174
  const logout = args.includes("--logout");
175
175
 
176
+ // Standalone update command (like docker updater)
177
+ const standaloneUpdate = args.includes("--update");
178
+ const updateDomain = args.includes("--domain") ? args[args.indexOf("--domain") + 1] : null;
179
+ const updateToken = args.includes("--token") ? args[args.indexOf("--token") + 1] : null;
180
+ const updateIp = args.includes("--ip") && args.indexOf("--ip") !== args.indexOf("--my-ip")
181
+ ? args[args.indexOf("--ip") + 1]
182
+ : null;
183
+
176
184
  // JSON output helper
177
185
  const jsonOutput = (data) => {
178
186
  if (showJson) {
@@ -226,6 +234,12 @@ ${chalk.bold("CONFIGURAZIONE:")}
226
234
  ${cyan("--logout")} Rimuovi configurazione locale
227
235
  ${cyan("--force")} Forza aggiornamento DNS
228
236
 
237
+ ${chalk.bold("AGGIORNAMENTO STANDALONE:")}
238
+ ${cyan("--update")} Aggiorna DNS via DynDNS2 (richiede --domain e --token)
239
+ ${cyan("--domain")} <name> Dominio da aggiornare (es: myhost.apertodns.com)
240
+ ${cyan("--token")} <token> Token DDNS per l'autenticazione
241
+ ${cyan("--ip")} <ip> IP da impostare (opzionale, auto-detect se omesso)
242
+
229
243
  ${chalk.bold("DAEMON MODE:")}
230
244
  ${cyan("--daemon")} Avvia in modalità daemon (aggiornamento continuo)
231
245
  ${cyan("--interval")} <sec> Intervallo aggiornamento daemon (default: 300s)
@@ -253,6 +267,8 @@ ${gray("Esempi:")}
253
267
  ${gray("$")} apertodns --test mioserver.apertodns.com
254
268
  ${gray("$")} apertodns --daemon --interval 60
255
269
  ${gray("$")} apertodns --api-key ak_xxx... --domains --json
270
+ ${gray("$")} apertodns --update --domain myhost.apertodns.com --token abc123
271
+ ${gray("$")} apertodns --update --domain myhost.apertodns.com --token abc123 --ip 1.2.3.4
256
272
 
257
273
  ${gray("Docs: https://apertodns.com/docs")}
258
274
  `);
@@ -1586,6 +1602,96 @@ const runDaemonMode = async () => {
1586
1602
  setInterval(update, daemonInterval * 1000);
1587
1603
  };
1588
1604
 
1605
+ // ==================== STANDALONE UPDATE (DynDNS2) ====================
1606
+
1607
+ const runStandaloneUpdate = async (domain, token, customIp) => {
1608
+ // Validate required parameters
1609
+ if (!domain || !token) {
1610
+ if (showJson) {
1611
+ console.log(JSON.stringify({
1612
+ error: "Parametri mancanti. Usa: --update --domain <domain> --token <token> [--ip <ip>]"
1613
+ }));
1614
+ } else {
1615
+ console.log(red("\n❌ Parametri mancanti."));
1616
+ console.log(gray(" Uso: apertodns --update --domain <domain> --token <token> [--ip <ip>]\n"));
1617
+ }
1618
+ process.exit(1);
1619
+ }
1620
+
1621
+ const spin = !showJson ? spinner("Aggiornamento DNS via DynDNS2...").start() : null;
1622
+
1623
+ try {
1624
+ // Get current IP if not provided
1625
+ let ipToUse = customIp;
1626
+ if (!ipToUse) {
1627
+ if (spin) spin.text = "Rilevamento IP pubblico...";
1628
+ ipToUse = await getCurrentIP('https://api.ipify.org');
1629
+ if (!ipToUse) {
1630
+ throw new Error("Impossibile rilevare IP pubblico");
1631
+ }
1632
+ ipToUse = ipToUse.trim();
1633
+ }
1634
+
1635
+ if (spin) spin.text = `Aggiornamento ${domain} → ${ipToUse}...`;
1636
+
1637
+ // Build DynDNS2 URL
1638
+ const updateUrl = `https://api.apertodns.com/nic/update?hostname=${encodeURIComponent(domain)}&myip=${encodeURIComponent(ipToUse)}`;
1639
+
1640
+ // Make request with Basic Auth (DynDNS2 protocol)
1641
+ const authHeader = 'Basic ' + Buffer.from(`${domain}:${token}`).toString('base64');
1642
+
1643
+ const res = await fetch(updateUrl, {
1644
+ method: 'GET',
1645
+ headers: {
1646
+ 'Authorization': authHeader,
1647
+ 'User-Agent': `ApertoDNS-CLI/${CURRENT_VERSION}`
1648
+ }
1649
+ });
1650
+
1651
+ const responseText = await res.text();
1652
+
1653
+ // Parse DynDNS2 response
1654
+ const isSuccess = responseText.startsWith('good') || responseText.startsWith('nochg');
1655
+
1656
+ if (isSuccess) {
1657
+ spin?.succeed(`DNS aggiornato! ${domain} → ${ipToUse}`);
1658
+
1659
+ if (showJson) {
1660
+ console.log(JSON.stringify({
1661
+ success: true,
1662
+ domain,
1663
+ ip: ipToUse,
1664
+ response: responseText.trim(),
1665
+ timestamp: new Date().toISOString()
1666
+ }, null, 2));
1667
+ } else if (!isCron) {
1668
+ console.log(` ${gray('Risposta:')} ${green(responseText.trim())}`);
1669
+ console.log();
1670
+ }
1671
+ } else {
1672
+ spin?.fail(`Errore aggiornamento: ${responseText.trim()}`);
1673
+
1674
+ if (showJson) {
1675
+ console.log(JSON.stringify({
1676
+ success: false,
1677
+ domain,
1678
+ ip: ipToUse,
1679
+ error: responseText.trim(),
1680
+ timestamp: new Date().toISOString()
1681
+ }, null, 2));
1682
+ }
1683
+ process.exit(1);
1684
+ }
1685
+ } catch (err) {
1686
+ spin?.fail(`Errore: ${err.message}`);
1687
+
1688
+ if (showJson) {
1689
+ console.log(JSON.stringify({ error: err.message }));
1690
+ }
1691
+ process.exit(1);
1692
+ }
1693
+ };
1694
+
1589
1695
  // ==================== LOGOUT ====================
1590
1696
 
1591
1697
  const runLogout = async () => {
@@ -1698,6 +1804,7 @@ const interactiveMode = async () => {
1698
1804
  const main = async () => {
1699
1805
  try {
1700
1806
  if (logout) await runLogout();
1807
+ else if (standaloneUpdate) await runStandaloneUpdate(updateDomain, updateToken, updateIp);
1701
1808
  else if (showMyIp) await showMyIpCommand();
1702
1809
  else if (runDaemon) await runDaemonMode();
1703
1810
  else if (enableTokenId) await updateTokenState(enableTokenId, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apertodns",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "ApertoDNS CLI - Dynamic DNS management from your terminal. Manage domains, tokens, API keys and DNS updates with style.",
5
5
  "main": "index.js",
6
6
  "type": "module",