mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
Using list view for both external addresses and hosted subnets
Every generated config files last line ends with a newline
This commit is contained in:
@@ -20,8 +20,10 @@
|
||||
<field>
|
||||
<id>host.extaddress</id>
|
||||
<label>Ext. Address</label>
|
||||
<type>text</type>
|
||||
<help>This machines external addresses to use (separated by comma)</help>
|
||||
<type>select_multiple</type>
|
||||
<style>tokenize</style>
|
||||
<allownew>true</allownew>
|
||||
<help>External address of selected machine</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>host.extport</id>
|
||||
@@ -32,7 +34,9 @@
|
||||
<field>
|
||||
<id>host.subnet</id>
|
||||
<label>Subnet</label>
|
||||
<type>text</type>
|
||||
<type>select_multiple</type>
|
||||
<style>tokenize</style>
|
||||
<allownew>true</allownew>
|
||||
<help>This machines part of the network</help>
|
||||
</field>
|
||||
<field>
|
||||
|
||||
+7
-3
@@ -68,8 +68,10 @@
|
||||
<field>
|
||||
<id>network.extaddress</id>
|
||||
<label>Ext. Address</label>
|
||||
<type>text</type>
|
||||
<help>This machines external addresses to use (separated by comma)</help>
|
||||
<type>select_multiple</type>
|
||||
<style>tokenize</style>
|
||||
<allownew>true</allownew>
|
||||
<help>External addresses of this machine</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>network.extport</id>
|
||||
@@ -80,7 +82,9 @@
|
||||
<field>
|
||||
<id>network.subnet</id>
|
||||
<label>Subnet</label>
|
||||
<type>text</type>
|
||||
<type>select_multiple</type>
|
||||
<style>tokenize</style>
|
||||
<allownew>true</allownew>
|
||||
<help>This machines part of the network</help>
|
||||
</field>
|
||||
<field>
|
||||
|
||||
@@ -21,9 +21,11 @@
|
||||
<mask>/^([0-9a-zA-Z\_]){1,1024}$/u</mask>
|
||||
<ValidationMessage>Please specify a valid hostname.</ValidationMessage>
|
||||
</hostname>
|
||||
<extaddress type="TextField">
|
||||
<extaddress type="HostnameField">
|
||||
<Required>N</Required>
|
||||
<mask>/^([0-9a-zA-Z\.,_\-:]){0,1024}$/u</mask>
|
||||
<IpAllowed>1</IpAllowed>
|
||||
<FieldSeparator>,</FieldSeparator>
|
||||
<AsList>Y</AsList>
|
||||
</extaddress>
|
||||
<extport type="IntegerField">
|
||||
<Required>Y</Required>
|
||||
@@ -41,6 +43,7 @@
|
||||
<WildcardEnabled>N</WildcardEnabled>
|
||||
<NetMaskRequired>Y</NetMaskRequired>
|
||||
<FieldSeparator>,</FieldSeparator>
|
||||
<AsList>Y</AsList>
|
||||
<Constraints>
|
||||
<check001>
|
||||
<ValidationMessage>Subnet field must be set in router mode.</ValidationMessage>
|
||||
@@ -131,15 +134,26 @@
|
||||
<MaximumValue>65535</MaximumValue>
|
||||
<ValidationMessage>Port number must be between 1...65535</ValidationMessage>
|
||||
</extport>
|
||||
<extaddress type="TextField">
|
||||
<extaddress type="HostnameField">
|
||||
<Required>N</Required>
|
||||
<mask>/^([0-9a-zA-Z\.,_\-:]){0,1024}$/u</mask>
|
||||
<IpAllowed>1</IpAllowed>
|
||||
<FieldSeparator>,</FieldSeparator>
|
||||
<AsList>Y</AsList>
|
||||
<Constraints>
|
||||
<check001>
|
||||
<ValidationMessage>Need external address if you intend to "Connect To" this host</ValidationMessage>
|
||||
<type>SetIfConstraint</type>
|
||||
<field>connectTo</field>
|
||||
<check>1</check>
|
||||
</check001>
|
||||
</Constraints>
|
||||
</extaddress>
|
||||
<subnet type="NetworkField">
|
||||
<Required>N</Required>
|
||||
<WildcardEnabled>N</WildcardEnabled>
|
||||
<NetMaskRequired>Y</NetMaskRequired>
|
||||
<FieldSeparator>,</FieldSeparator>
|
||||
<AsList>Y</AsList>
|
||||
</subnet>
|
||||
<pubkey type="TextField">
|
||||
<Required>Y</Required>
|
||||
@@ -154,6 +168,11 @@
|
||||
<connectTo type="BooleanField">
|
||||
<default>1</default>
|
||||
<Required>Y</Required>
|
||||
<Constraints>
|
||||
<check001>
|
||||
<reference>extaddress.check001</reference>
|
||||
</check001>
|
||||
</Constraints>
|
||||
</connectTo>
|
||||
<enabled type="BooleanField">
|
||||
<default>1</default>
|
||||
|
||||
@@ -30,6 +30,8 @@ class NetwConfObject(object):
|
||||
self._payload = dict()
|
||||
self._payload['hostname'] = None
|
||||
self._payload['network'] = None
|
||||
self._payload['address'] = ''
|
||||
self._payload['port'] = None
|
||||
|
||||
def is_valid(self):
|
||||
for key in self._payload:
|
||||
@@ -53,6 +55,11 @@ class NetwConfObject(object):
|
||||
def get_basepath(self):
|
||||
return '/usr/local/etc/tinc/%(network)s' % self._payload
|
||||
|
||||
def get_addresses(self):
|
||||
if not self._payload['address']:
|
||||
return
|
||||
yield from self._payload['address'].split(',')
|
||||
|
||||
class Network(NetwConfObject):
|
||||
def __init__(self):
|
||||
super(Network, self).__init__()
|
||||
@@ -95,10 +102,6 @@ class Network(NetwConfObject):
|
||||
def config_text(self):
|
||||
result = list()
|
||||
result.append('AddressFamily=any')
|
||||
if 'address' in self._payload:
|
||||
addresses = self._payload['address'].split(',')
|
||||
for address in addresses:
|
||||
result.append('Address=%s %s' % (address, self._payload['port']))
|
||||
result.append('Mode=%(mode)s' % self._payload)
|
||||
result.append('PMTUDiscovery=%(PMTUDiscovery)s' % self._payload)
|
||||
result.append('Port=%(port)s' % self._payload)
|
||||
@@ -108,7 +111,7 @@ class Network(NetwConfObject):
|
||||
result.append('ConnectTo = %s' % (host.get_hostname(),))
|
||||
result.append('Device=/dev/tinc%(id)s' % self._payload)
|
||||
result.append('Name=%(hostname)s' % self._payload)
|
||||
return '\n'.join(result)
|
||||
return '\n'.join(result) + '\n'
|
||||
|
||||
def filename(self):
|
||||
return self.get_basepath() + '/tinc.conf'
|
||||
@@ -129,7 +132,7 @@ class Host(NetwConfObject):
|
||||
self._payload['cipher'] = None
|
||||
|
||||
def connect_to_this_host(self):
|
||||
if self.is_valid() and self._connectTo == "1":
|
||||
if self.is_valid() and self._payload['address'] and self._connectTo == "1":
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -137,20 +140,21 @@ class Host(NetwConfObject):
|
||||
def set_connectto(self, value):
|
||||
self._connectTo = value.text
|
||||
|
||||
def get_subnets(self):
|
||||
if not self._payload['subnet']:
|
||||
return
|
||||
yield from self._payload['subnet'].split(',')
|
||||
|
||||
def config_text(self):
|
||||
result = list()
|
||||
if 'address' in self._payload:
|
||||
addresses = self._payload['address'].split(',')
|
||||
for address in addresses:
|
||||
result.append('Address=%s %s' % (address, self._payload['port']))
|
||||
if 'subnet' in self._payload:
|
||||
networks = self._payload['subnet'].split(',')
|
||||
for network in networks:
|
||||
result.append('Subnet=%s' % network)
|
||||
for address in self.get_addresses():
|
||||
result.append('Address=%s %s' % (address, self._payload['port']))
|
||||
for network in self.get_subnets():
|
||||
result.append('Subnet=%s' % network)
|
||||
result.append('Cipher=%(cipher)s'%self._payload)
|
||||
result.append('Digest=sha256')
|
||||
result.append(self._payload['pubkey'])
|
||||
return '\n'.join(result)
|
||||
return '\n'.join(result) + '\n'
|
||||
|
||||
def filename(self):
|
||||
return '%s/hosts/%s' % (self.get_basepath(), self._payload['hostname'])
|
||||
|
||||
Reference in New Issue
Block a user