summaryrefslogtreecommitdiffstats
path: root/installation/sdnc-web/src
diff options
context:
space:
mode:
authorMichael DÜrre <michael.duerre@highstreet-technologies.com>2022-01-27 13:43:37 +0100
committerMichael DÜrre <michael.duerre@highstreet-technologies.com>2022-01-27 14:01:45 +0100
commit38509f1fbad27de70eef1e81eaa2c5084765ca8f (patch)
tree71ee996cae9edba8e3806c8803f202e543ab9365 /installation/sdnc-web/src
parentbcdddcc342180eb1aa5cf8a9f1b4b84990d5f87d (diff)
improve sdnc-web for external apps
add package manager for more flexibility Issue-ID: SDNC-1658 Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com> Change-Id: I30f4aaa24cf05fce212282b06d5e08437dbcfa8b Signed-off-by: Michael DÜrre <michael.duerre@highstreet-technologies.com> Former-commit-id: f41f011ff2e18befd77dd63ab828ea14aafac2a7
Diffstat (limited to 'installation/sdnc-web/src')
-rw-r--r--installation/sdnc-web/src/main/docker/Dockerfile21
-rw-r--r--installation/sdnc-web/src/main/resources/favicon.icobin0 -> 268322 bytes
-rw-r--r--installation/sdnc-web/src/main/resources/http_site.conf33
-rw-r--r--installation/sdnc-web/src/main/resources/https_site.conf34
-rw-r--r--installation/sdnc-web/src/main/resources/location.rules46
-rw-r--r--installation/sdnc-web/src/main/resources/odlux.application.list9
-rw-r--r--installation/sdnc-web/src/main/scripts/configure.py34
-rw-r--r--installation/sdnc-web/src/main/scripts/configure.sh106
-rw-r--r--installation/sdnc-web/src/main/scripts/core.py333
-rwxr-xr-xinstallation/sdnc-web/src/main/scripts/opm.py126
-rw-r--r--installation/sdnc-web/src/main/scripts/run.sh11
11 files changed, 573 insertions, 180 deletions
diff --git a/installation/sdnc-web/src/main/docker/Dockerfile b/installation/sdnc-web/src/main/docker/Dockerfile
index a552137f..9f3f6870 100644
--- a/installation/sdnc-web/src/main/docker/Dockerfile
+++ b/installation/sdnc-web/src/main/docker/Dockerfile
@@ -22,12 +22,14 @@
# Base bitnami nginx image
FROM ${base.image.repo}
LABEL maintainer="CCSDK Team (onap-ccsdk@lists.onap.org)"
-
+USER root
+RUN apt-get update && apt-get install python3-minimal python3-urllib3 unzip openssl -y
+USER 1001
# copy ODLUX files to nginx
COPY html /opt/bitnami/nginx/html
# copy site conf files
-COPY *.conf /opt/bitnami/nginx/conf/server_blocks/
+COPY conf/* /opt/bitnami/nginx/conf/server_blocks/
# setup environment variables
ENV WEBPROTOCOL="HTTP" \
@@ -38,20 +40,25 @@ ENV WEBPROTOCOL="HTTP" \
TRPCEURL="" \
TOPOURL="" \
TILEURL="" \
- DNS_RESOLVER="1.1.1.1" \
+ SITEDOCURL="" \
+ DNS_RESOLVER="1.1.1.1 ipv6=off" \
+ DNS_INTERNAL_RESOLVER="127.0.0.11" \
SSL_CERT_DIR="/app/cert" \
SSL_CERTIFICATE="cert.pem" \
SSL_CERTIFICATE_KEY="cert.key"
# Check if /app can be used. If so, create "custom" directory and copy the files there.
-COPY bin/*.sh /opt/bitnami/nginx/sbin/
+COPY bin/* /opt/bitnami/nginx/sbin/
USER root
-RUN chmod +x /opt/bitnami/nginx/sbin/configure.sh /opt/bitnami/nginx/sbin/run.sh
+RUN chmod +x /opt/bitnami/nginx/sbin/run.sh /opt/bitnami/nginx/sbin/opm.py
# By default, docker copies files with the permissions of the build user. To avoid cases where build user
# has 644 which can result in failure of certain commands
-RUN chmod -R g+w /opt/bitnami/nginx/html/odlux
-
+RUN chmod -R g+w /opt/bitnami/nginx/html/odlux && mkdir /app/init.d
+RUN chmod 666 /opt/bitnami/nginx/conf/server_blocks/*.rules
+#RUN chown 1001:1001 /app/odlux.application.list && chmod 777 /app/odlux.application.list
+RUN chown -R 1001:1001 /app
+RUN ln -s /opt/bitnami/nginx/sbin/opm.py /usr/local/bin/opm
USER 1001
CMD [ "/opt/bitnami/nginx/sbin/run.sh" ]
diff --git a/installation/sdnc-web/src/main/resources/favicon.ico b/installation/sdnc-web/src/main/resources/favicon.ico
new file mode 100644
index 00000000..650067eb
--- /dev/null
+++ b/installation/sdnc-web/src/main/resources/favicon.ico
Binary files differ
diff --git a/installation/sdnc-web/src/main/resources/http_site.conf b/installation/sdnc-web/src/main/resources/http_site.conf
index ea6c33be..3d9ade13 100644
--- a/installation/sdnc-web/src/main/resources/http_site.conf
+++ b/installation/sdnc-web/src/main/resources/http_site.conf
@@ -49,36 +49,5 @@ server {
server_name _;
- location ~ ^/$ {
- return 301 /odlux/index.html;
- }
- location ~ ^/help/$ {
- try_files /help/$args.json $uri;
- }
- location ~ ^/transportpce {
- if ($request_uri ~* "/transportpce/(.*)") {
- proxy_pass TRPCEURL/$1;
- }
- }
- location ~ ^/topology {
- proxy_pass TOPOURL;
- }
- location ~ ^/tiles/ {
- resolver DNS_RESOLVER;
- if ($request_uri ~* "/tiles/(.*)") {
- proxy_pass TILEURL/$1;
- }
- }
- location / {
- try_files $uri $uri/ @backend;
- }
- location /websocket {
- proxy_pass SDNRPROTOCOL://SDNRHOST:SDNRPORT/websocket;
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection "upgrade";
- }
- location @backend {
- proxy_pass SDNRPROTOCOL://SDNRHOST:SDNRPORT;
- }
+ include server_blocks/location.rules;
}
diff --git a/installation/sdnc-web/src/main/resources/https_site.conf b/installation/sdnc-web/src/main/resources/https_site.conf
index 5e61fece..6dcfb790 100644
--- a/installation/sdnc-web/src/main/resources/https_site.conf
+++ b/installation/sdnc-web/src/main/resources/https_site.conf
@@ -68,36 +68,6 @@ server {
server_name _;
- location ~ ^/$ {
- return 301 /odlux/index.html;
- }
- location ~ ^/help/$ {
- try_files /help/$args.json $uri;
- }
- location ~ ^/transportpce {
- if ($request_uri ~* "/transportpce/(.*)") {
- proxy_pass TRPCEURL/$1;
- }
- }
- location ~ ^/topology {
- proxy_pass TOPOURL;
- }
- location ~ ^/tiles/ {
- resolver DNS_RESOLVER;
- if ($request_uri ~* "/tiles/(.*)") {
- proxy_pass TILEURL/$1;
- }
- }
- location / {
- try_files $uri $uri/ @backend;
- }
- location /websocket {
- proxy_pass SDNRPROTOCOL://SDNRHOST:SDNRPORT/websocket;
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection "upgrade";
- }
- location @backend {
- proxy_pass SDNRPROTOCOL://SDNRHOST:SDNRPORT;
- }
+ include server_blocks/location.rules;
+
}
diff --git a/installation/sdnc-web/src/main/resources/location.rules b/installation/sdnc-web/src/main/resources/location.rules
new file mode 100644
index 00000000..83120d60
--- /dev/null
+++ b/installation/sdnc-web/src/main/resources/location.rules
@@ -0,0 +1,46 @@
+location ~ ^/$ {
+ return 301 " /odlux/index.html";
+}
+location ~ ^/help/$ {
+ try_files /help/$args.json $uri;
+}
+location ~ ^/transportpce {
+ resolver DNS_INTERNAL_RESOLVER;
+ if ($request_uri ~* "/transportpce/(.*)") {
+ proxy_pass TRPCEURL/$1;
+ }
+}
+location ~ ^/topology/ {
+ resolver DNS_INTERNAL_RESOLVER;
+ proxy_pass TOPOURL;
+}
+location ~ ^/sitedoc/ {
+ resolver DNS_INTERNAL_RESOLVER;
+ if ($request_uri ~* "/sitedoc/(.*)") {
+ proxy_pass SITEDOCURL/topology/stadok/$1;
+ }
+}
+location ~ ^/tiles/ {
+ resolver DNS_RESOLVER;
+ if ($request_uri ~* "/tiles/(.*)") {
+ proxy_pass TILEURL/$1;
+ }
+}
+location ~ ^/terrain/ {
+ resolver DNS_INTERNAL_RESOLVER;
+ if ($request_uri ~* "/terrain/(.*)") {
+ proxy_pass TERRAINURL/$1;
+ }
+}
+location / {
+ try_files $uri $uri/ @backend;
+}
+location /websocket {
+ proxy_pass SDNRPROTOCOL://SDNRHOST:SDNRPORT/websocket;
+ proxy_http_version 1.1;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection "upgrade";
+}
+location @backend {
+ proxy_pass SDNRPROTOCOL://SDNRHOST:SDNRPORT;
+} \ No newline at end of file
diff --git a/installation/sdnc-web/src/main/resources/odlux.application.list b/installation/sdnc-web/src/main/resources/odlux.application.list
new file mode 100644
index 00000000..9176aae6
--- /dev/null
+++ b/installation/sdnc-web/src/main/resources/odlux.application.list
@@ -0,0 +1,9 @@
+1 connectApp
+10 faultApp
+20 maintenanceApp
+30 configurationApp
+55 performanceHistoryApp
+70 inventoryApp
+75 eventLogApp
+90 mediatorApp
+200 helpApp
diff --git a/installation/sdnc-web/src/main/scripts/configure.py b/installation/sdnc-web/src/main/scripts/configure.py
new file mode 100644
index 00000000..255cbcd5
--- /dev/null
+++ b/installation/sdnc-web/src/main/scripts/configure.py
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+###
+# ============LICENSE_START=======================================================
+# ONAP : ccsdk distribution web
+# ================================================================================
+# Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+# All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+
+# load core methods to call
+from core import *
+
+# Comment listening on 8080 in nginx.conf as we don't want nginx to listen on any port other than SDNR
+sedInFile('listen','\#listen', '/opt/bitnami/nginx/conf/nginx.conf')
+initial_load()
+update_index_html()
+
+check_for_rule_template()
+
+update_nginx_site_conf()
diff --git a/installation/sdnc-web/src/main/scripts/configure.sh b/installation/sdnc-web/src/main/scripts/configure.sh
deleted file mode 100644
index a257e6e1..00000000
--- a/installation/sdnc-web/src/main/scripts/configure.sh
+++ /dev/null
@@ -1,106 +0,0 @@
-#!/bin/bash
-
-###
-# ============LICENSE_START=======================================================
-# ONAP : ccsdk distribution web
-# ================================================================================
-# Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
-# All rights reserved.
-# ================================================================================
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-# ============LICENSE_END=========================================================
-###
-
-# Comment listening on 8080 in nginx.conf as we don't want nginx to listen on any port other than SDNR
-sed -i 's/listen/\#listen/g' /opt/bitnami/nginx/conf/nginx.conf
-
-update_index_html() {
-
- # Backup the index.html file
- cp /opt/bitnami/nginx/html/odlux/index.html /opt/bitnami/nginx/html/odlux/index.html.backup
- #default values
- ODLUX_AUTH_METHOD="basic"
- ENABLE_ODLUX_RBAC=${ENABLE_ODLUX_RBAC:-false}
-
- if [ "$ENABLE_OAUTH" == "true" ]; then
- ODLUX_AUTH_METHOD="oauth"
- fi
- echo "authentication is $ODLUX_AUTH_METHOD"
- echo "rbac access is enabled: $ENABLE_ODLUX_RBAC"
- ODLUX_CONFIG='{"authentication":"'$ODLUX_AUTH_METHOD'","enablePolicy":'$ENABLE_ODLUX_RBAC'}'
-# sed -z 's/<script>[^<]*<\/script>/<script>\n \/\/ run the application \n require\(\[\"connectApp\",\"faultApp\",\"maintenanceApp\",\"configurationApp\",\"performanceHistoryApp\",\"inventoryApp\",\"eventLogApp\",\"mediatorApp\",\"networkMapApp\",\"linkCalculationApp\",\"helpApp\",\"run\"\], function \(connectApp,faultApp,maintenanceApp,configurationApp,performanceHistoryApp,inventoryApp,eventLogApp,mediatorApp,networkMapApp,linkCalculationApp,helpApp,run\) \{ \n run.configure('$ODLUX_CONFIG'); \n connectApp.register\(\); \n faultApp.register\(\);\n maintenanceApp.register\(\); \n configurationApp.register\(\);\n performanceHistoryApp.register\(\); \n inventoryApp.register\(\);\n eventLogApp.register\(\);\n mediatorApp.register\(\);\n networkMapApp.register\(\);\n linkCalculationApp.register\(\);\n helpApp.register\(\);\n run.runApplication();\n \}\);\n <\/script>/' -i /opt/bitnami/nginx/html/odlux/index.html
-
- #replace require expression
- sed -z 's/require(\["run"\],\ function\ (run)/require\(\[\"connectApp\",\"faultApp\",\"maintenanceApp\",\"configurationApp\",\"performanceHistoryApp\",\"inventoryApp\",\"eventLogApp\",\"mediatorApp\",\"networkMapApp\",\"linkCalculationApp\",\"helpApp\",\"run\"\], function \(connectApp,faultApp,maintenanceApp,configurationApp,performanceHistoryApp,inventoryApp,eventLogApp,mediatorApp,networkMapApp,linkCalculationApp,helpApp,run\)/' -i /opt/bitnami/nginx/html/odlux/index.html
- #replace run.runApplication expression
- sed -z 's/run.runApplication();/connectApp.register\(\); \n faultApp.register\(\);\n maintenanceApp.register\(\); \n configurationApp.register\(\);\n performanceHistoryApp.register\(\); \n inventoryApp.register\(\);\n eventLogApp.register\(\);\n mediatorApp.register\(\);\n networkMapApp.register\(\);\n linkCalculationApp.register\(\);\n helpApp.register\(\);\n run.runApplication();/' -i /opt/bitnami/nginx/html/odlux/index.html
- #replace run.configure expression if exists
- sed -z 's/run.configureApplication([^)]\+)/run.configureApplication('$ODLUX_CONFIG');/' -i /opt/bitnami/nginx/html/odlux/index.html
-
-}
-
-update_nginx_site_conf() {
-
- if [ "$WEBPROTOCOL" == "HTTPS" ]
- then
- FN=/opt/bitnami/nginx/conf/server_blocks/https_site.conf
- rm /opt/bitnami/nginx/conf/server_blocks/http_site.conf
-
- sed -i 's|SSL_CERT_DIR|'$SSL_CERT_DIR'|g' $FN
- sed -i 's|\bSSL_CERTIFICATE\b|'$SSL_CERTIFICATE'|g' $FN
- sed -i 's|\bSSL_CERTIFICATE_KEY\b|'$SSL_CERTIFICATE_KEY'|g' $FN
-
- elif [ "$WEBPROTOCOL" == "HTTP" ]
- then
- FN=/opt/bitnami/nginx/conf/server_blocks/http_site.conf
- rm /opt/bitnami/nginx/conf/server_blocks/https_site.conf
- fi
-
- if [ -z "$FN" ]; then
- echo "unknown env WEBPROTOCOL: $WEBPROTOCOL"
- exit 1
- fi
-
- # replace needed parameters
- sed -i 's|WEBPORT|'$WEBPORT'|g' $FN
- sed -i 's|SDNRPROTOCOL|'$SDNRPROTOCOL'|g' $FN
- sed -i 's|SDNRHOST|'$SDNRHOST'|g' $FN
- sed -i 's|SDNRPORT|'$SDNRPORT'|g' $FN
- sed -i 's|DNS_RESOLVER|'$DNS_RESOLVER'|g' $FN
-
- # handle optional parameters
- if [ -z "$TRPCEURL" ]; then
- echo "transportPCE forwarding disabled"
- sed -i 's|proxy_pass TRPCEURL/$1;|return 404;|g' $FN
-
- else
- sed -i 's|TRPCEURL|'$TRPCEURL'|g' $FN
- fi
- if [ -z "$TOPOURL" ]; then
- echo "topology api forwarding disabled"
- sed -i 's|proxy_pass TOPOURL;|return 404;|g' $FN
- else
- sed -i 's|TOPOURL|'$TOPOURL'|g' $FN
- fi
- if [ -z "$TILEURL" ]; then
- echo "tile server forwarding disabled"
- sed -i 's|proxy_pass TILEURL/$1;|return 404;|g' $FN
- else
- sed -i 's|TILEURL|'$TILEURL'|g' $FN
- fi
-
-}
-
-update_index_html
-
-update_nginx_site_conf
diff --git a/installation/sdnc-web/src/main/scripts/core.py b/installation/sdnc-web/src/main/scripts/core.py
new file mode 100644
index 00000000..feb57348
--- /dev/null
+++ b/installation/sdnc-web/src/main/scripts/core.py
@@ -0,0 +1,333 @@
+###
+# ============LICENSE_START=======================================================
+# ONAP : ccsdk distribution web
+# ================================================================================
+# Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+# All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+import subprocess
+import os
+import json
+import zipfile
+import re
+import uuid
+import urllib3
+import shutil
+import re
+import ssl
+urllib3.disable_warnings()
+
+APPLICATION_LISTFILE="/app/odlux.application.list"
+INIT_FOLDER="/app/init.d"
+ODLUX_BASE_FOLDER='/app/odlux'
+INDEX_HTML=ODLUX_BASE_FOLDER+'/index.html'
+INDEX_HTML_TEMPLATE=INDEX_HTML+'.template'
+DEFAULT_APPLICATIONS=["connectApp" "faultApp" "maintenanceApp" "configurationApp" "performanceHistoryApp" "inventoryApp" "eventLogApp" "mediatorApp" "helpApp"]
+http = urllib3.PoolManager(cert_reqs=ssl.CERT_NONE)
+
+def exec(command):
+ output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout.read()
+ return output
+def execToStdOut(commandArray):
+ process = subprocess.Popen(commandArray, shell=False)
+ process.communicate()
+
+def download(url, dst):
+ print("downloading from {}...".format(url),end="")
+ with open(dst, 'wb') as out_file:
+ resp= http.request('GET',url, preload_content=False)
+ shutil.copyfileobj(resp, out_file)
+ resp.release_conn()
+ print("done")
+
+def getEnv(key, defaultValue=None):
+ x=os.getenv(key)
+ return x if x is not None and len(x)>0 else defaultValue
+
+def sedInFile(old, nu, fn):
+ execToStdOut(['sed', '-i', 's|{}|{}|g'.format(old,nu),fn])
+
+def add_application(name, index, file=None):
+ apps = load_applications()
+ if index==0:
+ print("no index given. put it to last position")
+ index=apps[len(apps)-1]['index']+10
+ apps.append(dict(index=index,name=name))
+ if file is not None and os.path.exists(file):
+ extract(file)
+ else:
+ print('unable to find file {}'.format(file))
+ write_applications(apps)
+ print("{} installed on index {}".format(name, index))
+
+def initial_load():
+ files = os.listdir(INIT_FOLDER)
+ regex = r"([0-9]+)([a-zA-Z]+)\.(jar|zip)"
+ for file in files:
+ matches = re.finditer(regex,file)
+ match = next(matches, None)
+ if match is not None:
+ print("installing {}".format(file))
+ index = int(match.group(1))
+ name = match.group(2)
+ add_application(name,index,INIT_FOLDER+'/'+file)
+ else:
+ print("no index naming format found. try to autodetect")
+ infos = autoDetectInfosFromJar(file)
+ if infos is None:
+ print("unable to detect index and application name for {}".format(file))
+ else:
+ add_application(infos['name'],infos['index'],INIT_FOLDER+'/'+file)
+
+
+
+def containsBlueprintExpression(file) -> bool:
+ print("check if file {} is blueprint".format(file))
+ with open(file, 'r') as fp:
+ lines = fp.readlines()
+ for line in lines:
+ if "<blueprint" in line:
+ return True
+ fp.close()
+ return False
+
+def findBlueprintXml(dir):
+ result = [os.path.join(dp, f) for dp, dn, filenames in os.walk(dir) for f in filenames if os.path.splitext(f)[1] == '.xml']
+ for file in result:
+ if containsBlueprintExpression(file):
+ return file
+ return None
+
+def autoDetectInfosFromJar(file):
+ print("autodetect infos(appName and index) from jar {}".format(file))
+ tmpDir=getRandomTempDir()
+ regexBundleName = r"<property[\ ]+name=\"bundleName\"[\ ]+value=\"([^\"]+)\""
+ regexIndex = r"<property[\ ]+name=\"index\"[\ ]+value=\"([^\"]+)\""
+ name=None
+ index=0
+ with zipfile.ZipFile(file, 'r') as zip_ref:
+ zip_ref.extractall(tmpDir)
+ blueprint = findBlueprintXml(tmpDir)
+ if blueprint is None:
+ return None
+ with open(blueprint) as fp:
+ lines = fp.readlines()
+ for line in lines:
+ if name is None:
+ matches = re.finditer(regexBundleName, line)
+ match = next(matches,None)
+ if match is not None:
+ name = match.group(1)
+ if index == 0:
+ matches = re.finditer(regexIndex, line)
+ match = next(matches,None)
+ if match is not None:
+ index = int(match.group(1))
+
+ fp.close()
+ print("found infos from jar: name={} index={}".format(name,index))
+ return dict(index=index,name=name)
+
+def getRandomTempDir(create=False):
+ while(True):
+ dir='/tmp/{}'.format(uuid.uuid4())
+ if not os.path.exists(dir):
+# print("found random not-existing dir {}".format(dir))
+ if create:
+ os.makedirs(dir)
+ return dir
+# print("dir {} already exists. try new".format(dir))
+ return None
+
+def getRandomTempFile():
+ dir = getRandomTempDir(True)
+ if dir is None:
+ return None
+
+ while True:
+ file='{}/{}.dat'.format(dir,uuid.uuid4())
+ if not os.path.exists(file):
+# print("found random not-existing file {}".format(file))
+ return file
+# print("file {} already exists. try new".format(file))
+ return None
+
+def extract(fn):
+
+ tmpDir=getRandomTempDir()
+ with zipfile.ZipFile(fn, 'r') as zip_ref:
+ zip_ref.extractall(tmpDir)
+ exec(" ".join(['cp','-r',tmpDir+'/odlux/*',ODLUX_BASE_FOLDER+'/']))
+ zip_ref.close()
+
+
+def load_applications():
+ apps=[]
+ if os.path.exists(APPLICATION_LISTFILE):
+ with open(APPLICATION_LISTFILE,'r') as fp:
+ lines= fp.readlines()
+ for line in lines:
+ if len(line.rstrip())<=0:
+ continue
+ try:
+ hlp=line.split(' ')
+ apps.append(dict(index=int(hlp[0]),name=hlp[1].rstrip()))
+ except:
+ print('problem reading line {}'.format(line))
+ fp.close()
+ else:
+ index=10
+ for app in DEFAULT_APPLICATIONS:
+ apps.append(dict(index=index,name=app))
+ index+=10
+# print('applications loaded={}'.format(apps))
+ return sorted(apps, key=lambda d: d['index'])
+
+def write_applications(apps):
+# print('saving applications={}'.format(apps))
+ apps = sorted(apps, key=lambda d: d['index'])
+ os.remove(APPLICATION_LISTFILE)
+ with open(APPLICATION_LISTFILE,'w') as fp:
+ for app in apps:
+ fp.write('{} {}\n'.format(app['index'], app['name']))
+ fp.close()
+
+def update_index_html(apps=None):
+
+# # Backup the index.html file
+ if not os.path.exists(INDEX_HTML_TEMPLATE):
+ execToStdOut(['cp',INDEX_HTML,INDEX_HTML_TEMPLATE])
+ else:
+ execToStdOut(['cp',INDEX_HTML_TEMPLATE,INDEX_HTML])
+# #default values
+ if apps is None:
+ apps=load_applications()
+ ODLUX_AUTH_METHOD="basic"
+ ENABLE_ODLUX_RBAC=getEnv('ENABLE_ODLUX_RBAC','false')
+ TRPCEGUIURL=getEnv('TRPCEGUIURL')
+
+ if getEnv('ENABLE_OAUTH') == "true":
+ ODLUX_AUTH_METHOD="oauth"
+ ODLUX_CONFIG=dict(authentication=ODLUX_AUTH_METHOD,enablePolicy=ENABLE_ODLUX_RBAC == 'true')
+ print("authentication is {}".format(ODLUX_AUTH_METHOD))
+ print("rbac access is enabled: {}".format(ENABLE_ODLUX_RBAC))
+
+ if TRPCEGUIURL is not None:
+ ODLUX_CONFIG['transportpceUrl']=TRPCEGUIURL
+ print("trpce gui url is: {}".format(TRPCEGUIURL))
+
+# sed -z 's/<script>[^<]*<\/script>/<script>\n \/\/ run the application \n require\(\[\"connectApp\",\"faultApp\",\"maintenanceApp\",\"configurationApp\",\"performanceHistoryApp\",\"inventoryApp\",\"eventLogApp\",\"mediatorApp\",\"networkMapApp\",\"linkCalculationApp\",\"helpApp\",\"run\"\], function \(connectApp,faultApp,maintenanceApp,configurationApp,performanceHistoryApp,inventoryApp,eventLogApp,mediatorApp,networkMapApp,linkCalculationApp,helpApp,run\) \{ \n run.configure('$ODLUX_CONFIG'); \n connectApp.register\(\); \n faultApp.register\(\);\n maintenanceApp.register\(\); \n configurationApp.register\(\);\n performanceHistoryApp.register\(\); \n inventoryApp.register\(\);\n eventLogApp.register\(\);\n mediatorApp.register\(\);\n networkMapApp.register\(\);\n linkCalculationApp.register\(\);\n helpApp.register\(\);\n run.runApplication();\n \}\);\n <\/script>/' -i /opt/bitnami/nginx/html/odlux/index.html
+ requireArg=""
+ fnArgs=""
+ appCalls=""
+ for app in apps:
+ requireArg+='"{}",'.format(app['name'])
+ fnArgs+='{},'.format(app['name'])
+ appCalls+='{}.register();\\n'.format(app['name'])
+ #replace require expression
+ execToStdOut(['sed', '-z', 's/require(\["run"\],\ function\ (run)/require\(\[{}\"run\"\], function \({}run\)/'.format(requireArg,fnArgs), '-i', INDEX_HTML])
+ #replace run.runApplication expression
+ execToStdOut(['sed','-z', 's/run.runApplication();/{}run.runApplication();/'.format(appCalls), '-i',INDEX_HTML])
+ #replace run.configure expression if exists
+ execToStdOut(['sed', '-z', 's|run.configureApplication([^)]\+)|run.configureApplication({});|'.format(json.dumps(ODLUX_CONFIG)), '-i', INDEX_HTML])
+
+
+def check_for_rule_template():
+ if os.path.exists('/opt/bitnami/nginx/conf/server_blocks/location.rules.tmpl'):
+ print("using template for forwarding rules")
+ execToStdOut(['cp','/opt/bitnami/nginx/conf/server_blocks/location.rules.tmpl','/opt/bitnami/nginx/conf/server_blocks/location.rules'])
+
+def update_nginx_site_conf():
+ FN=None
+ if getEnv('WEBPROTOCOL') == "HTTPS":
+ FN='/opt/bitnami/nginx/conf/server_blocks/https_site.conf'
+ execToStdOut(['rm', '/opt/bitnami/nginx/conf/server_blocks/http_site.conf'])
+ SSL_CERT_DIR=getEnv('SSL_CERT_DIR')
+ SSL_CERTIFICATE=getEnv('SSL_CERTIFICATE')
+ SSL_CERTIFICATE_KEY=getEnv('SSL_CERTIFICATE_KEY')
+ sedInFile('SSL_CERTIFICATE_KEY',SSL_CERTIFICATE_KEY,FN)
+ sedInFile('SSL_CERT_DIR',SSL_CERT_DIR,FN)
+ sedInFile('SSL_CERTIFICATE',SSL_CERTIFICATE, FN)
+
+ elif getEnv('WEBPROTOCOL') == "HTTP":
+ FN='/opt/bitnami/nginx/conf/server_blocks/http_site.conf'
+ execToStdOut(['rm', '/opt/bitnami/nginx/conf/server_blocks/https_site.conf'])
+
+ WEBPROTOCOL=getEnv('WEBPROTOCOL')
+ WEBPORT=getEnv('WEBPORT')
+ SDNRPROTOCOL=getEnv('SDNRPROTOCOL')
+ SDNRHOST=getEnv('SDNRHOST')
+ SDNRPORT=getEnv('SDNRPORT')
+ DNS_RESOLVER=getEnv('DNS_RESOLVER')
+ DNS_INTERNAL_RESOLVER=getEnv('DNS_INTERNAL_RESOLVER')
+ if FN is None:
+ print("unknown env WEBPROTOCOL: {}".format(WEBPROTOCOL))
+ exit(1)
+
+ # replace needed base parameters
+ sedInFile('WEBPORT',WEBPORT,FN)
+
+ FN='/opt/bitnami/nginx/conf/server_blocks/location.rules'
+ # replace needed parameters in forwarding rules
+ sedInFile('WEBPORT',WEBPORT,FN)
+ sedInFile('SDNRPROTOCOL',SDNRPROTOCOL,FN)
+ sedInFile('SDNRHOST',SDNRHOST ,FN)
+ sedInFile('SDNRPORT',SDNRPORT,FN)
+ sedInFile('DNS_RESOLVER',DNS_RESOLVER ,FN)
+ sedInFile('DNS_INTERNAL_RESOLVER',DNS_INTERNAL_RESOLVER ,FN)
+
+ TRPCEURL=getEnv('TRPCEURL')
+ TOPOURL=getEnv('TOPOURL')
+ SITEDOCURL=getEnv('SITEDOCURL')
+ TILEURL=getEnv('TILEURL')
+ DATAPROVIDERURL=getEnv('DATAPROVIDERURL')
+ TERRAINURL=getEnv('TERRAINURL')
+ # handle optional parameters
+ if TRPCEURL is None:
+ print("transportPCE forwarding disabled")
+ sedInFile('proxy_pass TRPCEURL/$1;','return 404;',FN)
+ else:
+ sedInFile('TRPCEURL',TRPCEURL ,FN)
+
+ if TOPOURL is None:
+ print("topology api forwarding disabled")
+ sedInFile('proxy_pass TOPOURL;','return 404;',FN)
+ else:
+ sedInFile('TOPOURL',TOPOURL ,FN)
+
+ if SITEDOCURL is None:
+ print("sitedoc api forwarding disabled")
+ sedInFile('proxy_pass SITEDOCURL/topology/stadok/$1;','return 404;', FN)
+ else:
+ sedInFile('SITEDOCURL',SITEDOCURL, FN)
+
+ if TILEURL is None:
+ print("tile server forwarding disabled")
+ sedInFile('proxy_pass TILEURL/$1;','return 404;',FN)
+ else:
+ sedInFile('TILEURL',TILEURL ,FN)
+
+ if DATAPROVIDERURL is None:
+ print("data provider forwarding disabled")
+ sedInFile('proxy_pass DATAPROVIDERURL/$1;','return 404;',FN)
+ else:
+ sedInFile('DATAPROVIDERURL',DATAPROVIDERURL ,FN)
+
+ if TERRAINURL is None:
+ print("terrain server forwarding disabled")
+ sedInFile('proxy_pass TERRAINURL/$1;','return 404;',FN)
+ else:
+ sedInFile('TERRAINURL',TERRAINURL ,FN)
diff --git a/installation/sdnc-web/src/main/scripts/opm.py b/installation/sdnc-web/src/main/scripts/opm.py
new file mode 100755
index 00000000..955822aa
--- /dev/null
+++ b/installation/sdnc-web/src/main/scripts/opm.py
@@ -0,0 +1,126 @@
+#!/usr/bin/python3
+###
+# ============LICENSE_START=======================================================
+# ONAP : ccsdk distribution web
+# ================================================================================
+# Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
+# All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+
+# opm = ODLUX package manager
+# install odlux application inside of the container
+# $1 install|uninstall
+# $2 appName
+# $3 zip file to add(extract)
+
+import sys
+from core import *
+
+
+
+
+# install application
+# $1 appName
+# $2
+# $2 zip file (optional)
+def run_install(name, index=0, file=None):
+ if name is None:
+ error("no name given")
+ add_application(name, index, file)
+ update_index_html()
+
+
+# install application from url
+# $1 url
+# $2 name (optional)
+# $3 index (optional)
+def run_install_from_url(url, name=None, index=0):
+ if url is None:
+ error("no url given")
+ print("installing from url...")
+ localFile = getRandomTempFile()
+ download(url,localFile)
+ if (name is None) or (index==0):
+ infos = autoDetectInfosFromJar(localFile)
+ if infos is not None:
+ if name is None:
+ name = infos['name']
+ if index == 0:
+ index = infos['index']
+ add_application(name,index,localFile)
+
+# uninstall application
+# $1 appName
+def run_uninstall(name):
+ if name is None:
+ error("no name given")
+ apps = load_applications()
+ apps = [app for app in apps if app['name']!=name]
+ write_applications(apps)
+ update_index_html()
+
+def run_list(args):
+ apps = load_applications()
+ print('installed apps')
+ for app in apps:
+ print('{} {}'.format(app['index'],app['name']))
+
+def print_help():
+ print("ODLUX package manager")
+ print("=====================")
+ print("usage:")
+ print(" opm.py install --name myApplication --index 23 --file app.zip")
+ print(" opm.py install --url https://link-to-my-odlux-application.jar")
+ print(" opm.py list")
+ print(" opm.py uninstall --name myApplication")
+
+def error(msg):
+ print('ERROR: {}'.format(msg))
+ exit(1)
+
+args = sys.argv
+args.pop(0)
+cmd = args.pop(0)
+name=None
+index=0
+file=None
+url=None
+while(len(args)>0):
+ x=args.pop(0)
+ if x=='--name':
+ name=args.pop(0) if len(args)>0 else error("no name given")
+ elif x=='--index':
+ index=int(args.pop(0)) if len(args)>0 else error("no index given")
+ elif x=='--file':
+ file=args.pop(0) if len(args)>0 else error("no file given")
+ elif x=='--url':
+ url=args.pop(0) if len(args)>0 else error("no file given")
+
+print("command={} name={} index={} file={} url={}".format(cmd,name,index, file, url))
+
+if cmd=='install':
+ if url is not None:
+ run_install_from_url(url, name, index)
+ else:
+ run_install(name,index,file)
+elif cmd=='uninstall':
+ run_uninstall(name)
+elif cmd=='list':
+ run_list(args)
+else:
+ print_help
+ exit(1)
+exit(0)
diff --git a/installation/sdnc-web/src/main/scripts/run.sh b/installation/sdnc-web/src/main/scripts/run.sh
index c310837f..3343faf4 100644
--- a/installation/sdnc-web/src/main/scripts/run.sh
+++ b/installation/sdnc-web/src/main/scripts/run.sh
@@ -21,19 +21,24 @@
#============LICENSE_END=========================================================
###
-/opt/bitnami/nginx/sbin/configure.sh
+python3 /opt/bitnami/nginx/sbin/configure.py
echo "starting sdnc-web"
-echo "================="
+echo "======================="
echo " WEBPROTOCOL : $WEBPROTOCOL"
echo " WEBPORT : $WEBPORT"
echo " SDNRPROTOCOL : $SDNRPROTOCOL"
echo " SDNRHOST : $SDNRHOST"
echo " SDNRPORT : $SDNRPORT"
echo " DNS_RESOLVER : $DNS_RESOLVER"
+echo " DNS_INTERNAL_RESOLVER : $DNS_INTERNAL_RESOLVER"
echo " TRPCEURL : $TRPCEURL"
+echo " TRPCEGUIURL : $TRPCEGUIURL"
echo " TOPOURL : $TOPOURL"
echo " TILEURL : $TILEURL"
+echo " SITEDOCURL : $SITEDOCURL"
+echo " TERRAINURL : $TERRAINURL"
+echo "======================="
if [ "$WEBPROTOCOL" == "HTTPS" ]; then
echo " SSL_CERT_DIR : $SSL_CERT_DIR"
echo -n " SSL_CERTIFICATE: $SSL_CERTIFICATE"
@@ -71,4 +76,4 @@ if [ ! -z "$DEBUG" ]; then
fi
# Call the base images' run.sh to start NGINX
-bash /run.sh
+bash /opt/bitnami/scripts/nginx/run.sh