From 73180232179b6dcd8836cb0bc4e5e37a93980ba8 Mon Sep 17 00:00:00 2001 From: Felix Engelmann Date: Sun, 16 Sep 2018 18:24:33 +0200 Subject: [PATCH 01/14] show list of ip addresses with CIDR netmask for network interfaces --- app/ui/templates/container-details.html | 40 ++++++++++--------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/app/ui/templates/container-details.html b/app/ui/templates/container-details.html index 351ca7e5..f714a9ca 100644 --- a/app/ui/templates/container-details.html +++ b/app/ui/templates/container-details.html @@ -247,7 +247,7 @@
+
  • Interface {{ key }} @@ -260,34 +260,27 @@
    +
      {% if value.addresses == None %}
    • N/A
    • {% else %} - {% if value.addresses|length > 0 %} - IP Address {{value.addresses.0.address}} - {% endif %} -
    • - MAC Address {{value.hwaddr}} -
    • -
    • - {% if value.addresses|length > 0 %} - {% if value.addresses.0.netmask == "24" %} - Netmask [/{{value.addresses.0.netmask}}] 255.255.255.0 - {% else %} - - {% if value.addresses.0.netmask != "24" %} - Netmask [/{{value.addresses.0.netmask}}] [/{{value.addresses.0.netmask}}] - {% endif %} - - {% endif %} - {% endif %} -
    • + {% for address in value.addresses %} +
    • + IP{% if address.family == 'inet' %}v4{% elif address.family == 'inet6' %}v6{% endif %} Address + {{address.address}}/{{address.netmask}} +
    • + {% endfor %} +
    • + MAC Address {{value.hwaddr}} +
    • {% endif %}
    -
    +
    + +
    +
    @@ -315,9 +308,6 @@
    - - From dac0387ac8bf0f6651611f7668979c51fe794652 Mon Sep 17 00:00:00 2001 From: Felix Engelmann Date: Thu, 20 Sep 2018 00:59:38 +0200 Subject: [PATCH 02/14] main functionality with remote lxd socket, terminal not working --- app/__metadata__.py | 2 ++ app/api/models/LXDModule.py | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/__metadata__.py b/app/__metadata__.py index 4eb34166..b99f1391 100644 --- a/app/__metadata__.py +++ b/app/__metadata__.py @@ -23,6 +23,8 @@ [LXDUI] lxdui.port = 15151 lxdui.images.remote = https://images.linuxcontainers.org +#lxdui.lxd.remote = https://lxd.host.org:8443/ +#lxdui.lxd.sslverify = true lxdui.jwt.token.expiration = 1200 lxdui.jwt.secret.key = AC8d83&21Almnis710sds lxdui.jwt.auth.url.rule = /api/user/login diff --git a/app/api/models/LXDModule.py b/app/api/models/LXDModule.py index a74047b9..24b39ab3 100644 --- a/app/api/models/LXDModule.py +++ b/app/api/models/LXDModule.py @@ -12,8 +12,28 @@ class LXDModule(Base): # Default 127.0.0.1 -> Move to Config def __init__(self, remoteHost='127.0.0.1'): + + conf = Config() logging.info('Accessing PyLXD client') - self.client = Client() + try: + remoteHost = Config().get(meta.APP_NAME, '{}.lxd.remote'.format(meta.APP_NAME.lower())) + sslKey = conf.get(meta.APP_NAME, '{}.ssl.key'.format(meta.APP_NAME.lower())) + sslCert = conf.get(meta.APP_NAME, '{}.ssl.cert'.format(meta.APP_NAME.lower())) + sslVerify = conf.get(meta.APP_NAME, '{}.lxd.sslverify'.format(meta.APP_NAME.lower())) + + if sslVerify.lower in ['true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly']: + sslVerify = True + else: + sslVerify = False + + self.client = Client(endpoint=remoteHost, + cert=(sslCert, sslKey), verify=sslVerify) + except: + logging.info('using local socket') + self.client = Client() + + + def listContainers(self): try: From 8ae145e6f28d1ac8831fee4cc48eefdb7f089838 Mon Sep 17 00:00:00 2001 From: Felix Engelmann Date: Thu, 20 Sep 2018 18:31:55 +0200 Subject: [PATCH 03/14] use superclass instead of new pylxd connection --- app/api/models/LXCFileManager.py | 2 +- app/api/models/LXCNetwork.py | 2 +- app/api/models/LXCProfile.py | 2 +- app/api/models/LXCStoragePool.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/api/models/LXCFileManager.py b/app/api/models/LXCFileManager.py index 0fe7f0e2..a84c49ce 100644 --- a/app/api/models/LXCFileManager.py +++ b/app/api/models/LXCFileManager.py @@ -8,7 +8,7 @@ class LXCFileManager(LXDModule): def __init__(self, input): logging.info('Connecting to LXD') - self.client = Client() + super().__init__() self.input = input def list(self): diff --git a/app/api/models/LXCNetwork.py b/app/api/models/LXCNetwork.py index 9e809682..8a1ad79d 100644 --- a/app/api/models/LXCNetwork.py +++ b/app/api/models/LXCNetwork.py @@ -14,7 +14,7 @@ class LXCNetwork(LXDModule): def __init__(self, input): logging.info('Connecting to LXD') - self.client = Client() + super().__init__() logging.debug('Setting network input to {}'.format(input)) self.input = input diff --git a/app/api/models/LXCProfile.py b/app/api/models/LXCProfile.py index d408f8c5..12cb9a6e 100644 --- a/app/api/models/LXCProfile.py +++ b/app/api/models/LXCProfile.py @@ -8,7 +8,7 @@ class LXCProfile(LXDModule): def __init__(self, input): logging.info('Connecting to LXD') - self.client = Client() + super().__init__() self.input = input def info(self): diff --git a/app/api/models/LXCStoragePool.py b/app/api/models/LXCStoragePool.py index 4f15af9e..39f3498d 100644 --- a/app/api/models/LXCStoragePool.py +++ b/app/api/models/LXCStoragePool.py @@ -8,7 +8,7 @@ class LXCStoragePool(LXDModule): def __init__(self, input): logging.info('Connecting to LXD') - self.client = Client() + super().__init__() self.input = input def info(self): From 3414dbdd090b58016cfa9544c2557bf21e3841bc Mon Sep 17 00:00:00 2001 From: Felix Engelmann Date: Tue, 22 Jan 2019 00:29:13 +0100 Subject: [PATCH 04/14] reformatted network view to fit in one line and calculate prefixes --- app/ui/templates/container-details.html | 65 +++++++++++++++++++------ 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/app/ui/templates/container-details.html b/app/ui/templates/container-details.html index f714a9ca..ebf25c21 100644 --- a/app/ui/templates/container-details.html +++ b/app/ui/templates/container-details.html @@ -247,7 +247,7 @@
    +
    • Interface {{ key }} @@ -260,43 +260,73 @@
      +
        {% if value.addresses == None %}
      • N/A
      • {% else %} +
      • + MAC Address {{value.hwaddr}} +
      • {% for address in value.addresses %}
      • IP{% if address.family == 'inet' %}v4{% elif address.family == 'inet6' %}v6{% endif %} Address {{address.address}}/{{address.netmask}}
      • {% endfor %} -
      • - MAC Address {{value.hwaddr}} -
      • {% endif %}
      -
      - -
      -
      +
    - - - - + + - - - + +
    Sent Received
    Bytes{{'%0.2f'|format(container.network[key]['counters']['bytes_received']/1024)}}{{'%0.2f'|format(container.network[key]['counters']['bytes_sent']/1024)}}{% if container.network[key]['counters']['bytes_sent'] > 1610612736 %} + {{'%0.2f'|format(container.network[key]['counters']['bytes_sent']/1073741824)}} GiB + {% elif container.network[key]['counters']['bytes_sent'] > 1572864 %} + {{'%0.2f'|format(container.network[key]['counters']['bytes_sent']/1048576)}} MiB + {% elif container.network[key]['counters']['bytes_sent'] > 1536 %} + {{'%0.2f'|format(container.network[key]['counters']['bytes_sent']/1024)}} kiB + {% else %} + {{'%0.2f'|format(container.network[key]['counters']['bytes_sent'])}} B + {% endif %} + {% if container.network[key]['counters']['bytes_received'] > 1610612736 %} + {{'%0.2f'|format(container.network[key]['counters']['bytes_received']/1073741824)}} GiB + {% elif container.network[key]['counters']['bytes_received'] > 1572864 %} + {{'%0.2f'|format(container.network[key]['counters']['bytes_received']/1048576)}} MiB + {% elif container.network[key]['counters']['bytes_received'] > 1536 %} + {{'%0.2f'|format(container.network[key]['counters']['bytes_received']/1024)}} kiB + {% else %} + {{'%0.2f'|format(container.network[key]['counters']['bytes_received'])}} B + {% endif %} +
    Packets{{container.network[key]['counters']['packets_sent']}}{{container.network[key]['counters']['packets_received']}}{% if container.network[key]['counters']['packets_sent'] > 1500000000 %} + {{'%0.2f'|format(container.network[key]['counters']['packets_sent']/1500000000)}} Gpkts + {% elif container.network[key]['counters']['packets_sent'] > 1500000 %} + {{'%0.2f'|format(container.network[key]['counters']['packets_sent']/1000000)}} Mpkts + {% elif container.network[key]['counters']['packets_sent'] > 1500 %} + {{'%0.2f'|format(container.network[key]['counters']['packets_sent']/1000)}} kpkts + {% else %} + {{'%0.2f'|format(container.network[key]['counters']['packets_sent'])}} pkts + {% endif %} + {% if container.network[key]['counters']['packets_received'] > 1500000000 %} + {{'%0.2f'|format(container.network[key]['counters']['packets_received']/1500000000)}} Gpkts + {% elif container.network[key]['counters']['packets_received'] > 1500000 %} + {{'%0.2f'|format(container.network[key]['counters']['packets_received']/1000000)}} Mpkts + {% elif container.network[key]['counters']['packets_received'] > 1500 %} + {{'%0.2f'|format(container.network[key]['counters']['packets_received']/1000)}} kpkts + {% else %} + {{'%0.2f'|format(container.network[key]['counters']['packets_received'])}} pkts + {% endif %} +
    @@ -308,6 +338,9 @@
    + +
    From d8e06c12e6b5c1fdbcb9d4a386ccdf345ab3e83e Mon Sep 17 00:00:00 2001 From: Ye Yang Date: Mon, 25 Jan 2021 15:17:24 +0000 Subject: [PATCH 05/14] Added PAM authentication. --- app/__metadata__.py | 2 ++ app/lib/auth.py | 34 +++++++++++++++++++++++++++++++++- requirements.txt | 1 + 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/__metadata__.py b/app/__metadata__.py index b99f1391..24514f10 100644 --- a/app/__metadata__.py +++ b/app/__metadata__.py @@ -25,6 +25,8 @@ lxdui.images.remote = https://images.linuxcontainers.org #lxdui.lxd.remote = https://lxd.host.org:8443/ #lxdui.lxd.sslverify = true +#lxdui.group = sudo +#lxdui.pam = true lxdui.jwt.token.expiration = 1200 lxdui.jwt.secret.key = AC8d83&21Almnis710sds lxdui.jwt.auth.url.rule = /api/user/login diff --git a/app/lib/auth.py b/app/lib/auth.py index 40eb1e9a..519c40a6 100644 --- a/app/lib/auth.py +++ b/app/lib/auth.py @@ -4,6 +4,9 @@ import json import hashlib import logging +import pam +import grp +import pwd log = logging.getLogger(__name__) @@ -119,6 +122,35 @@ def update(self, username, password): self.save(self.users) def authenticate(self, username, password): + try: + pam_auth = conf.Config().get(meta.APP_NAME,'lxdui.pam') + if pam_auth == 'true': + if pam.authenticate(username,password): + try: + lxdui_group = conf.Config().get(meta.APP_NAME,'lxdui.group') + + # get user groups + groups = [g.gr_name for g in grp.getgrall() if username in g.gr_mem] + gid = pwd.getpwnam(username).pw_gid + groups.append(grp.getgrgid(gid).gr_name) + + for g in groups: + if g == lxdui_group: + return True, 'Authenticated' + + return False, 'No required permissions.' + except: + # lxdui_group authentication was not chosen + return True, 'Authenticated' + else: + return False, 'Incorrect password.' + else: + return self.authenticate_sha(username, password) + except: + # PAM authentication was not chosen + return self.authenticate_sha(username, password) + + def authenticate_sha(self, username, password): account, err = self.get(username) if account is None: @@ -127,4 +159,4 @@ def authenticate(self, username, password): if account['password'] == self.sha_password(password): return True, 'Authenticated' else: - return False, 'Incorrect password.' + return False, 'Incorrect password.' \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 1f49b201..199f166c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,7 @@ psutil==5.4.5 pylxd==2.2.7 terminado==0.8.1 tornado==5.0.2 +python-pam==1.8.4 tornado-xstatic XStatic==1.0.1 XStatic-term.js==0.0.7.0 From ec192922f0e122b6c3a4015814c05940c8a8b068 Mon Sep 17 00:00:00 2001 From: Ye Yang Date: Fri, 21 Jan 2022 17:24:38 +0000 Subject: [PATCH 06/14] Fixed pyyaml version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7f552747..ed3ed7aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,4 +16,4 @@ tornado-xstatic XStatic==1.0.1 XStatic-term.js==0.0.7.0 bcrypt==3.2.0 -pyyaml==5.4 +pyyaml==3.11 From a09517c532e17c4e98b47025e216c52c44e4b018 Mon Sep 17 00:00:00 2001 From: Ye Yang Date: Mon, 24 Jan 2022 11:21:52 +0000 Subject: [PATCH 07/14] Revert "Added PAM authentication." This reverts commit d8e06c12e6b5c1fdbcb9d4a386ccdf345ab3e83e. --- app/__metadata__.py | 2 -- app/lib/auth.py | 32 -------------------------------- requirements.txt | 1 - 3 files changed, 35 deletions(-) diff --git a/app/__metadata__.py b/app/__metadata__.py index 2cf63633..43a32a04 100644 --- a/app/__metadata__.py +++ b/app/__metadata__.py @@ -26,8 +26,6 @@ lxdui.images.remote = https://images.linuxcontainers.org #lxdui.lxd.remote = https://lxd.host.org:8443/ #lxdui.lxd.sslverify = true -#lxdui.group = sudo -#lxdui.pam = true #lxdui.lxd.remote.name = host lxdui.jwt.token.expiration = 1200 lxdui.jwt.secret.key = AC8d83&21Almnis710sds diff --git a/app/lib/auth.py b/app/lib/auth.py index 1d7af604..62373e41 100644 --- a/app/lib/auth.py +++ b/app/lib/auth.py @@ -4,9 +4,6 @@ import json import hashlib import logging -import pam -import grp -import pwd import bcrypt log = logging.getLogger(__name__) @@ -127,35 +124,6 @@ def update(self, username, password): self.save(self.users) def authenticate(self, username, password): - try: - pam_auth = conf.Config().get(meta.APP_NAME,'lxdui.pam') - if pam_auth == 'true': - if pam.authenticate(username,password): - try: - lxdui_group = conf.Config().get(meta.APP_NAME,'lxdui.group') - - # get user groups - groups = [g.gr_name for g in grp.getgrall() if username in g.gr_mem] - gid = pwd.getpwnam(username).pw_gid - groups.append(grp.getgrgid(gid).gr_name) - - for g in groups: - if g == lxdui_group: - return True, 'Authenticated' - - return False, 'No required permissions.' - except: - # lxdui_group authentication was not chosen - return True, 'Authenticated' - else: - return False, 'Incorrect password.' - else: - return self.authenticate_sha(username, password) - except: - # PAM authentication was not chosen - return self.authenticate_sha(username, password) - - def authenticate_sha(self, username, password): account, err = self.get(username) if account is None: diff --git a/requirements.txt b/requirements.txt index ed3ed7aa..a2361c7e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,6 @@ psutil==5.6.6 pylxd==2.2.11 terminado==0.8.1 tornado==5.0.2 -python-pam==1.8.4 tornado-xstatic XStatic==1.0.1 XStatic-term.js==0.0.7.0 From b5256299aa928e509acd1af61ce1eb72fde10559 Mon Sep 17 00:00:00 2001 From: Ye Yang Date: Mon, 24 Jan 2022 17:55:58 +0000 Subject: [PATCH 08/14] Added interface to clone instance configuration --- app/ui/templates/containers.html | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/ui/templates/containers.html b/app/ui/templates/containers.html index 3a66b0f8..462abcd9 100644 --- a/app/ui/templates/containers.html +++ b/app/ui/templates/containers.html @@ -107,6 +107,12 @@ title="Clone Container"> Clone
  • +
  • + + Clone +
+ + +