diff --git a/archetypes/blog.md b/archetypes/blog.md new file mode 100644 index 0000000..d05c049 --- /dev/null +++ b/archetypes/blog.md @@ -0,0 +1,8 @@ +--- +title: "{{ replace .Name "-" " " | title }}" +description: "" +date: {{ .Date }} +author: "Ettore Dreucci" +tags: [] +draft: true +--- \ No newline at end of file diff --git a/config.toml b/config.toml index 103261b..d663e80 100644 --- a/config.toml +++ b/config.toml @@ -10,10 +10,9 @@ author = "Ettore Dreucci" title = "Ettore Dreucci" disqusshortname = "" pluralizelisttitles = false -disableKinds = ["taxonomy", "taxonomyTerm"] [permalinks] -blog = "blog/:slug/" +blog = "blog/:filename/" [params] dateform = "2 Jan 2006" @@ -26,6 +25,7 @@ highlightjs = true progressively = true align_left = false lang = "en" +latestpostcount = 5 github = "noettore" #email = "ettore.dreucci@gmail.com" linkedin = "ettore-dreucci-403110175" @@ -33,3 +33,4 @@ linkedin = "ettore-dreucci-403110175" social_banner = "img/banner.png" posts_navigation = true small_banner_logo = true + diff --git a/content/blog/ispconfig-ddns.md b/content/blog/ispconfig-ddns.md new file mode 100644 index 0000000..115d6e8 --- /dev/null +++ b/content/blog/ispconfig-ddns.md @@ -0,0 +1,123 @@ +--- +title: "ISPConfig Dynamic DNS" +tags: ["ispconfig", "ddns", "dns"] +categories: ["recipe"] +description: "How to create and update a DDNS entry in ISPConfig" +date: 2019-05-22T18:54:00+02:00 +draft: false +--- + +If you manage your DNS server(s) with ISPConfig you may want a *dynamic entry* that gets updated automatically every time the target host changes its IP address. + +Doing so in ISPConfig is quite straight forward: we can use the [ISPConfig SOAP API](https://git.ispconfig.org/ispconfig/ispconfig3/tree/master/remoting_client) to update an existing record with a PHP script to be run frequently by the target host. + +In this [**recipe**]({{< ref "/categories/recipe" >}}) I will consider **updating an A record**. + +1. First we need to create a remote user on the ISPConfig master server to authenticate, and grant it remote access and some functions: + + In “System -> Remote User” add a new remote user, enable remote access and **grant** “DNS zone functions” and each DNS functions corresponding to the type of record you want to update: **so if you want to update an A record you must grant the generic “DNS zone functions” and the “DNS a functions”** + +2. We then have to write a PHP script that will make a SOAP function call to the ISPConfig endpoint. The target host, or the host executing the script must have the [PHP SOAP module](https://www.php.net/manual/en/book.soap.php) installed. + + Create the `update.php` script as follow: +``` +3) { + // Third parameter: IP address of target host + $ip = $argv[3]; +// Otherwise +} else { + // Figure out the public IP of this host: + $ip = trim(file_get_contents("http://icanhazip.com/")); + if (filter_var($ip, FILTER_VALIDATE_IP) === false) { + die("Unable to retrieve public IP address (icanhazip.com returned $ip)\n"); + } +} + +print("Setting DDNS host $ddns_host.$domain to IP $ip\n"); + +// Using the SOAP module initialize a SoapClient +$client = new SoapClient(null, + array('location' => $soap_location, + 'uri' => $soap_uri, + 'trace' => 1, + 'exceptions' => 1)); + +try { + // Login to SOAP server + $session_id = $client->login($soap_user, $soap_password); + + // Grab DNS zone ID + $zone_id = $client->dns_zone_get_id($session_id, $domain); + // Grab DNS zone + $zone = $client->dns_zone_get($session_id, $zone_id); + // Grab DNS records + $records = $client->dns_rr_get_all_by_zone($session_id, $zone_id); + + // Find right record: hostname must match and type must be A + $dns_record = null; + foreach ($records as $rec) { + if ($rec['type']=='A' && $rec['name']==$ddns_host) { + $dns_record = $rec; + } + } + // If no record found + if (is_null($dns_record)) { + //Logout from SOAP server + $client->logout($session_id); + die("Unable to find DNS record for host $ddns_host in domain $domain on the server...\n"); + } + // If IP stored in record is different from current IP + if ($dns_record['data'] != $ip) { + // Set new IP + $dns_record['data'] = $ip; + // Increment record serial number + $dns_record['serial'] = $dns_record['serial']+1; + // Update modified record in DNS server + $client->dns_a_update($session_id, null, $dns_record['id'], $dns_record); + + // Increment zone serial number + $zone['serial'] = $zone['serial'] + 1; + // Update modified zone in DNS server + $client->dns_zone_update($session_id, 0, $zone_id, $zone); + + print("Successfully set DNS entry for host $ddns_host in domain $domain to $ip.\n"); + // Otherwise + } else { + print("IP address of $ddns_host.$domain already set to $ip.\n"); + } + + //Logout from SOAP server + $client->logout($session_id); + +} catch (SoapFault $e) { + die('SOAP Error: '.$e->getMessage()."\n"); +} + +?> +``` + + Create the `config.php` as follow: +``` +}} \ No newline at end of file +{{< figure src="img/calvin_hobbes/lastMinutePanic.png" link="https://www.calvinandhobbes.com/" target="_blank" title="copyright by Andrews McMeel Publishing" >}} \ No newline at end of file diff --git a/layouts/taxonomy/category.terms.html b/layouts/taxonomy/category.terms.html new file mode 100644 index 0000000..99cfaf7 --- /dev/null +++ b/layouts/taxonomy/category.terms.html @@ -0,0 +1,16 @@ +{{ partial "header.html" . }} +
+
+
+
+
{{ .Title }}
+ +
+
+
+
+{{ partial "footer.html" . }} \ No newline at end of file diff --git a/layouts/taxonomy/tag.terms.html b/layouts/taxonomy/tag.terms.html new file mode 100644 index 0000000..bae0c90 --- /dev/null +++ b/layouts/taxonomy/tag.terms.html @@ -0,0 +1,16 @@ +{{ partial "header.html" . }} +
+
+
+
+
{{ .Title }}
+
    + {{ range $name, $taxonomy := .Site.Taxonomies.tags }} + {{ $name }}
    + {{ end }} +
+
+
+
+
+{{ partial "footer.html" . }} \ No newline at end of file diff --git a/public/404.html b/public/404.html index 082f1e3..88150ec 100644 --- a/public/404.html +++ b/public/404.html @@ -325,6 +325,9 @@ div.main .content .front-matter .meta { display: flex; margin-bottom: 32px; } +div.main .content .front-matter .desc { + display: block; +} div.main .content .front-matter .date, div.main .content .front-matter .author, div.main .content .front-matter .tags, @@ -332,6 +335,7 @@ div.main .content .front-matter .word-count, div.main .content .front-matter .middot:before { display: none; } + div.main .content .front-matter .middot:before { font-size: 6px; margin: 0 6px; diff --git a/public/about/index.html b/public/about/index.html index 71b38b1..e6d9f4c 100644 --- a/public/about/index.html +++ b/public/about/index.html @@ -352,6 +352,9 @@ div.main .content .front-matter .meta { display: flex; margin-bottom: 32px; } +div.main .content .front-matter .desc { + display: block; +} div.main .content .front-matter .date, div.main .content .front-matter .author, div.main .content .front-matter .tags, @@ -359,6 +362,7 @@ div.main .content .front-matter .word-count, div.main .content .front-matter .middot:before { display: none; } + div.main .content .front-matter .middot:before { font-size: 6px; margin: 0 6px; @@ -1008,6 +1012,12 @@ margin-left: -4%;