mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
dns / ddclient - Add current ip address and updated timestamp to search api and grid
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
PLUGIN_NAME= ddclient
|
||||
PLUGIN_VERSION= 1.6
|
||||
PLUGIN_VERSION= 1.7
|
||||
PLUGIN_DEPENDS= ddclient
|
||||
PLUGIN_COMMENT= Dynamic DNS client
|
||||
PLUGIN_MAINTAINER= ad@opnsense.org
|
||||
|
||||
@@ -6,6 +6,10 @@ WWW: https://github.com/ddclient/ddclient
|
||||
Plugin Changelog
|
||||
================
|
||||
|
||||
1.7
|
||||
|
||||
* Add current ip address and updated timestamp to search api and grid
|
||||
|
||||
1.6
|
||||
|
||||
* Add Gandi support (contributed by Neozlag)
|
||||
|
||||
+4
-1
@@ -41,7 +41,10 @@ class AccountsController extends ApiMutableModelControllerBase
|
||||
{
|
||||
$result = $this->searchBase(
|
||||
"accounts.account",
|
||||
['enabled', 'service', 'description', 'username', 'hostnames', 'use_interface', 'interface', 'protocol'],
|
||||
[
|
||||
'enabled', 'service', 'description', 'username', 'hostnames', 'use_interface',
|
||||
'interface', 'protocol', 'current_ip', 'current_mtime'
|
||||
],
|
||||
"description"
|
||||
);
|
||||
foreach ($result['rows'] as &$row) {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
</daemon_delay>
|
||||
</general>
|
||||
<accounts>
|
||||
<account type="ArrayField">
|
||||
<account type=".\AccountField">
|
||||
<enabled type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>Y</Required>
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2022 Deciso B.V.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OPNsense\DynDNS\FieldTypes;
|
||||
|
||||
use OPNsense\Base\FieldTypes\ArrayField;
|
||||
use OPNsense\Base\FieldTypes\TextField;
|
||||
use OPNsense\Base\FieldTypes\IntegerField;
|
||||
use OPNsense\Core\Backend;
|
||||
use OPNsense\Core\Config;
|
||||
|
||||
class AccountField extends ArrayField
|
||||
{
|
||||
private static $current_stats = null;
|
||||
|
||||
private function addStatsFields($node)
|
||||
{
|
||||
// generate new unattached fields, which are only usable to read data from (not synched to config.xml)
|
||||
$current_ip = new TextField();
|
||||
$current_ip->setInternalIsVirtual();
|
||||
$current_mtime = new TextField();
|
||||
$current_mtime->setInternalIsVirtual();
|
||||
|
||||
if (!empty((string)$node->hostnames)) {
|
||||
foreach (explode(",", (string)$node->hostnames) as $hostname) {
|
||||
if (!empty((self::$current_stats[$hostname]))) {
|
||||
$stats = self::$current_stats[$hostname];
|
||||
$current_ip->setValue($stats['ip']);
|
||||
$current_mtime->setValue(date('c', $stats['mtime']));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$node->addChildNode('current_ip', $current_ip);
|
||||
$node->addChildNode('current_mtime', $current_mtime);
|
||||
}
|
||||
|
||||
protected function actionPostLoadingEvent()
|
||||
{
|
||||
if (self::$current_stats === null) {
|
||||
self::$current_stats = [];
|
||||
$stats = json_decode((new Backend())->configdRun('ddclient statistics'), true);
|
||||
if (!empty($stats) && !empty($stats['hosts'])) {
|
||||
self::$current_stats = $stats['hosts'];
|
||||
}
|
||||
}
|
||||
foreach ($this->internalChildnodes as $node) {
|
||||
if (!$node->getInternalIsVirtual()) {
|
||||
$this->addStatsFields($node);
|
||||
}
|
||||
}
|
||||
return parent::actionPostLoadingEvent();
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
<th data-column-id="hostnames" data-type="string">{{ lang._('Hostnames') }}</th>
|
||||
<th data-column-id="username" data-type="string">{{ lang._('Username') }}</th>
|
||||
<th data-column-id="interface" data-type="string">{{ lang._('Interface') }}</th>
|
||||
<th data-column-id="current_ip" data-type="string">{{ lang._('Current IP') }}</th>
|
||||
<th data-column-id="current_mtime" data-type="string">{{ lang._('Updated') }}</th>
|
||||
<th data-column-id="description" data-type="string">{{ lang._('Description') }}</th>
|
||||
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
|
||||
</tr>
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#!/usr/local/bin/python3
|
||||
|
||||
"""
|
||||
Copyright (c) 2022 Ad Schellevis <ad@opnsense.org>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
"""
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
filename = "/var/tmp/ddclient.cache"
|
||||
|
||||
result = {"hosts": {}}
|
||||
if os.path.isfile(filename):
|
||||
with open(filename, "r") as fhandle:
|
||||
for idx, row in enumerate(fhandle):
|
||||
if idx == 0:
|
||||
result['version'] = row.strip('#\n ')
|
||||
elif idx == 1:
|
||||
tmp = row.split('(')[-1].split(')')[0]
|
||||
if tmp.isdigit():
|
||||
result['updated'] = int(tmp)
|
||||
elif tmp.startswith('#') is False:
|
||||
record = {}
|
||||
for pair in row.split(','):
|
||||
parts = pair.split('=')
|
||||
if len(parts) == 2:
|
||||
record[parts[0]] = parts[1]
|
||||
if 'host' in record:
|
||||
result['hosts'][record['host']] = record
|
||||
|
||||
print(json.dumps(result))
|
||||
@@ -23,3 +23,8 @@ description:Restart ddclient service
|
||||
command:/usr/local/etc/rc.d/ddclient reload
|
||||
type:script
|
||||
message:reload ddclient configuration
|
||||
|
||||
[statistics]
|
||||
command:/usr/local/opnsense/scripts/ddclient/stats
|
||||
type:script_output
|
||||
message:get ddclient statistics
|
||||
|
||||
Reference in New Issue
Block a user