google-ddns
Version:
Google Dynamic DNS client update tool. Updates the DNS IP address to the current public IP.
2,403 lines (664 loc) • 33.3 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: DynamicDNS</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: DynamicDNS</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>
<span class="ancestors"><a href="DEDA-Google-DDNS.html">DEDA-Google-DDNS</a>.</span>DynamicDNS<span class="signature">(options)</span><span class="type-signature"></span></h2>
<div class="class-description"><p>This class provides an interface to get the currently set public and dns IP as well as update the Google DNS IP address.
Currently only IPv4 is supported but this the class is setup to be expended to support IPv6.</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="DynamicDNS"><span class="type-signature"></span>new DynamicDNS<span class="signature">(options)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Creates a new class with the given options.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>See <a href="DEDA-Google-DDNS.DynamicDNS.html#.getDefaultOptions">getDefaultOptions()</a> for more details.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-author">Author:</dt>
<dd class="tag-author">
<ul>
<li><a href="mailto:charbel.choueiri@gmail.com">Charbel Choueiri</a></li>
</ul>
</dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line23">line 23</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id=".ApiResponses"><span class="type-signature">(static, readonly) </span>ApiResponses<span class="type-signature"></span></h4>
<div class="description">
<p>This is a static array that contains a list of all the possible Google API responses to the update query.
This is used to return the result to the caller.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line117">line 117</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="https://support.google.com/domains/answer/6147083?hl=en">https://support.google.com/domains/answer/6147083?hl=en</a></li>
</ul>
</dd>
</dl>
<h4 class="name" id="currentIP"><span class="type-signature"></span>currentIP<span class="type-signature"> :string</span></h4>
<div class="description">
<p>Holds the current set host name IP address.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line41">line 41</a>
</li></ul></dd>
</dl>
<h4 class="name" id="lastGotHostIpAddress"><span class="type-signature"></span>lastGotHostIpAddress<span class="type-signature"> :number</span></h4>
<div class="description">
<p>Holds the time stamp the last time the host IP address was resolved. This is used in conjunction with <code>hostIPAddressCacheExpires</code> to
determine if we need to resolve the host IP address again. This is only used if <code>useHostIPAddressCache</code> is set to true.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line48">line 48</a>
</li></ul></dd>
</dl>
<h4 class="name" id="options"><span class="type-signature"></span>options<span class="type-signature"> :<a href="DEDA-Google-DDNS.DynamicDNS.html#.DefaultOptions">DEDA-Google-DDNS.DynamicDNS.DefaultOptions</a></span></h4>
<div class="description">
<p>The class options as defined by <a href="DEDA-Google-DDNS.DynamicDNS.html#.getDefaultOptions">getDefaultOptions()</a>
On initialization the constructor options parameters are merged with the default options.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><a href="DEDA-Google-DDNS.DynamicDNS.html#.DefaultOptions">DEDA-Google-DDNS.DynamicDNS.DefaultOptions</a></span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line61">line 61</a>
</li></ul></dd>
</dl>
<h4 class="name" id="publicIP"><span class="type-signature"></span>publicIP<span class="type-signature"> :string</span></h4>
<div class="description">
<p>Holds the current public IP address.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line35">line 35</a>
</li></ul></dd>
</dl>
<h4 class="name" id="unresolvedHostNameError"><span class="type-signature"></span>unresolvedHostNameError<span class="type-signature"> :number</span></h4>
<div class="description">
<p>Keeps track of the number of unresolved host name error. This is used to throw an exception if the maxUnresolvedHostNameFail is reached.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line54">line 54</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id=".getDefaultOptions"><span class="type-signature">(static) </span>getDefaultOptions<span class="signature">()</span><span class="type-signature"> → {<a href="DEDA-Google-DDNS.DynamicDNS.html#.DefaultOptions">DEDA-Google-DDNS.DynamicDNS.DefaultOptions</a>}</span></h4>
<div class="description">
<p>Returns a list of all possible options for this class with their default values.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line90">line 90</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Returns the component default options.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="DEDA-Google-DDNS.DynamicDNS.html#.DefaultOptions">DEDA-Google-DDNS.DynamicDNS.DefaultOptions</a></span>
</dd>
</dl>
<h4 class="name" id="getCurrentIP"><span class="type-signature"></span>getCurrentIP<span class="signature">()</span><span class="type-signature"> → {promise}</span></h4>
<div class="description">
<p>Uses the DNS protocol to resolve a IPv4 addresses (A records) for the hostname.
NOTE: This can and may return multiple IP addresses as of this version only the first IP address is returned. This can be extended to support multiple IPs in the future.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line226">line 226</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Returns a promise that is resolved when the host IP address is resolve. Otherwise rejected with an error message.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">promise</span>
</dd>
</dl>
<h4 class="name" id="getPublicIP"><span class="type-signature"></span>getPublicIP<span class="signature">()</span><span class="type-signature"> → {Promise}</span></h4>
<div class="description">
<p>Returns a promise with the public IP address of the current network hosting this application.
This method uses the HTTP GET url <code>options.publicIpUrl</code> to fetch the external IP address.
This method can be overwritten to extend or implement different methods of fetching the external/public IP.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line185">line 185</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Returns a promise that is resolved with the public IP if successful otherwise returns an error object {error: message}.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
<h4 class="name" id="parseResult"><span class="type-signature"></span>parseResult<span class="signature">(body, expectedIP, currentIP)</span><span class="type-signature"> → {<a href="DEDA-Google-DDNS.DynamicDNS.html#.ApiResponse">DEDA-Google-DDNS.DynamicDNS.ApiResponse</a>}</span></h4>
<div class="description">
<p>Pareses the Update request body and returns an object the represents the results.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>body</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>The HTTP update response body as sent back from the request.</p></td>
</tr>
<tr>
<td class="name"><code>expectedIP</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>The expected IP address that the update should have changed to. This is used to validate the result.</p></td>
</tr>
<tr>
<td class="name"><code>currentIP</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>The current IP address of the dom before it was changed. This is used for message reporting only.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line317">line 317</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="DEDA-Google-DDNS.DynamicDNS.html#.ApiResponses">DEDA-Google-DDNS.DynamicDNS.ApiResponses</a></li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>Returns the response that response the given body.</li>
</ul>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="DEDA-Google-DDNS.DynamicDNS.html#.ApiResponse">DEDA-Google-DDNS.DynamicDNS.ApiResponse</a></span>
</dd>
</dl>
<h4 class="name" id="sync"><span class="type-signature">(async) </span>sync<span class="signature">(force<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise}</span></h4>
<div class="description">
<p>Synchronizes the DNS IP address with the current public IP address. This method will get the current
IP and the DNS IP and compare them. If they have changed then a request is sent to Google to update the current IP
address. This is an asynchronous method that returns a promise when current status.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>force</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last"><p>Forces the update of the DNS regardless if it has changed or not.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line139">line 139</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Returns a promise that is resolved with the status of the sync call.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
<h4 class="name" id="update"><span class="type-signature"></span>update<span class="signature">(ip)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Sends a request using the Google Domain Dynamic DNS API to update the IP address to the current IP address.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>ip</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>The IP address to update the Google Dynamic DNS.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line257">line 257</a>
</li></ul></dd>
</dl>
<h4 class="name" id="validateIPv4"><span class="type-signature"></span>validateIPv4<span class="signature">(ip)</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
<p>Checks if the given IP address is a valid IPv4 address.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>ip</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>And IPv4 address to validate.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line348">line 348</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Returns true if the given ip is valid otherwise returns false.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h3 class="subsection-title">Type Definitions</h3>
<h4 class="name" id=".ApiResponse">ApiResponse</h4>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Object</span>
</li>
</ul>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>response</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>The response code as defined by the Google API</p></td>
</tr>
<tr>
<td class="name"><code>status</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>This could either be 'success' or 'error'</p></td>
</tr>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>A full human readable description of the response. This is provided for both the error and success status.</p></td>
</tr>
<tr>
<td class="name"><code>ip</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>If the response is either 'good' or 'nochg' then the IP address is the IP that is currently set for the domain DNS.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line299">line 299</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".DefaultOptions">DefaultOptions</h4>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Object</span>
</li>
</ul>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>username</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last"><p>The dynamic DNS username.</p></td>
</tr>
<tr>
<td class="name"><code>password</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last"><p>The dynamic DNS password.</p></td>
</tr>
<tr>
<td class="name"><code>hostname</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last"><p>The dynamic DNS hostname.</p></td>
</tr>
<tr>
<td class="name"><code>publicIpUrl</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
https://domains.google.com/checkip
</td>
<td class="description last"><p>The HTTP/HTTPS URL used to check the current public IP of the device.</p></td>
</tr>
<tr>
<td class="name"><code>updateIpUrl</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
https://domains.google.com/nic/update?hostname=%HOSTNAME%&myip=%IPADDRESS%
</td>
<td class="description last"><p>The HTTPS URL of the Google DNS API update.</p></td>
</tr>
<tr>
<td class="name"><code>userAgent</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
Nodejs google-ddns
</td>
<td class="description last"><p>The HTTP header User-Agent to send when updating the IP address. This is required by the Google Dynamic DNS API.</p></td>
</tr>
<tr>
<td class="name"><code>failOnUnresolvedHostName</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last"><p>Indicates whether to fail or keep going during synchronizing if the current host name was not resolved.
This typically happens if the domain was created and has not yet been applied or propagated. See TTL (Time-to-Live) for more information.
Every though this can fail the update can sill be successful.</p></td>
</tr>
<tr>
<td class="name"><code>maxUnresolvedHostNameFail</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
3
</td>
<td class="description last"><p>This works in conjunction with failOnUnresolvedHostName to make sure we don't keep failing over and over with no
error back reporting.</p></td>
</tr>
<tr>
<td class="name"><code>useHostIPAddressCache</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last"><p>Indicates whether to cache and use the last resolved host IP address or resolve every-time. Generally speaking we
don't need to resolve the host every-time since it will not change unless we change it. This saves having to do a DNS request every interval. Use the hostIPAddressCacheExpires
to do a check every once in a while.</p></td>
</tr>
<tr>
<td class="name"><code>hostIPAddressCacheExpires</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
3600
</td>
<td class="description last"><p>If useHostIPAddressCache is set to true, this timer is used to force a host IP address checked/resolution every once
in a while rather than never. The time is in seconds and defaults to every hour.</p></td>
</tr>
<tr>
<td class="name"><code>debug</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last"><p>Set the debug mode on or off. The debug mode will write debug and status information to the console.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_DynamicDNS.js.html">lib/DynamicDNS.js</a>, <a href="lib_DynamicDNS.js.html#line64">line 64</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="DEDA-Google-DDNS.DynamicDNS.html">DynamicDNS</a></li><li><a href="DEDA-Google-DDNS.Options.html">Options</a></li><li><a href="DEDA-Google-DDNS.Service.html">Service</a></li></ul><h3>Namespaces</h3><ul><li><a href="DEDA-Google-DDNS.html">DEDA-Google-DDNS</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Jul 01 2018 11:49:49 GMT-0400 (Eastern Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>