Start devel LR v0.4.9:

- Rest manager updated
- Service manager updated
- Dockerfiles updated

Change-Id: Ibbedbdd092201d716157588fb00268a6f45eba28
This commit is contained in:
Nicola Peditto 2019-04-23 14:25:59 +02:00
parent 80aa81ac4b
commit 0e235fcdf3
9 changed files with 160 additions and 28 deletions

View File

@ -127,7 +127,7 @@ def get_version(package):
def get_socket_info(wport):
lr_mac = "N/A"
sock_bundle = "N/A"
try:
for socks in psutil.Process().connections():
@ -146,14 +146,19 @@ def get_socket_info(wport):
for snicaddr in dct[iface]:
if snicaddr.family == 17:
lr_mac = snicaddr.address
return [iface, ip_addr, lr_mac]
else:
lr_mac = "N/A"
sock_bundle = [iface, ip_addr, lr_mac]
return sock_bundle
except Exception as e:
LOG.warning("Error getting socket info " + str(e))
lr_mac = "N/A"
return lr_mac
sock_bundle = "N/A"
return sock_bundle
return lr_mac
return sock_bundle
def backupConf():

View File

@ -190,6 +190,17 @@ class RestManager(Module.Module):
return
def change_hostname(hostname):
if hostname != "":
bashCommand = "hostname %s " % (hostname)
process = subprocess.Popen(bashCommand.split(),
stdout=subprocess.PIPE)
output, error = process.communicate()
else:
print("- No hostname specified!")
return
def lr_install():
bashCommand = "lr_install"
process = subprocess.Popen(bashCommand.split(),
@ -376,6 +387,10 @@ class RestManager(Module.Module):
ragent = request.form['urlwagent']
code = request.form['code']
lr_config(ragent, code)
hostname = request.form['hostname']
change_hostname(hostname)
return redirect("/status", code=302)
elif request.form.get('rst_btn') == 'RESTORE':
@ -392,6 +407,11 @@ class RestManager(Module.Module):
utils.LR_restart_delayed(5)
return redirect("/", code=302)
elif request.form.get('change_hostname'):
hostname = request.form['hostname']
change_hostname(hostname)
return redirect("/system", code=302)
elif request.form.get('rst_settings_btn'):
print("Settings restoring from uploaded backup...")

View File

@ -108,6 +108,10 @@ class ServiceManager(Module.Module):
for _ in range(get_zombies()):
try:
os.waitpid(-1, os.WNOHANG)
LOG.debug(
" - [finalize] WSTUN zombie " +
"process cleaned."
)
except Exception as exc:
print(" - [finalize] Error cleaning" +
" wstun zombie process: " + str(exc))
@ -210,14 +214,19 @@ class ServiceManager(Module.Module):
try:
os.kill(service_pid, signal.SIGINT)
LOG.debug(
" - [finalize] WSTUN process " +
"[" + str(wstun.pid) + "] killed")
print("OLD WSTUN KILLED: " + str(wp))
try:
os.waitpid(-1, os.WNOHANG)
print(" - OLD wstun zombie "
"process cleaned.")
LOG.warning(
" - OLD wstun zombie " +
"process cleaned."
)
except Exception as exc:
print(
LOG.warning(
" - [finalize] " +
"Error cleaning old " +
"wstun zombie process: " +
@ -235,7 +244,7 @@ class ServiceManager(Module.Module):
" - WSTUN process already killed, "
"creating new one...")
break
# break
# 2. Create the reverse tunnel
public_port = \
@ -317,9 +326,28 @@ class ServiceManager(Module.Module):
LOG.warning("WSTUN ALIVE: " + str(p))
wstun_process_list.append(p)
psutil.Process(p.pid).kill()
LOG.warning(" --> PID " + str(p.pid)
+ " killed!")
try:
psutil.Process(p.pid).kill()
LOG.warning(" --> PID " + str(p.pid)
+ " killed!")
try:
os.waitpid(-1, os.WNOHANG)
LOG.debug(
" - [restore] WSTUN zombie " +
"process cleaned."
)
except Exception as exc:
LOG.warning(
" - [restore] " +
"Error cleaning old " +
"wstun zombie process: " +
str(exc)
)
except OSError as err:
LOG.warning(
" - [restore] WSTUN killing problem: "
+ str(err)
)
except Exception as e:
LOG.error(
" --> PSUTIL [restore]: " +
@ -400,7 +428,7 @@ class ServiceManager(Module.Module):
message = "WSTUN zombie process ALERT!"
print(" - " + str(message))
LOG.debug("[WSTUN-RESTORE] --> " + str(message))
LOG.debug(" - [WSTUN-RESTORE] - " + str(message))
wstun_found = True
@ -418,6 +446,10 @@ class ServiceManager(Module.Module):
# Clean Zombie wstun process
try:
os.waitpid(-1, os.WNOHANG)
LOG.debug(
" - [_zombie_hunter] WSTUN zombie " +
"process cleaned."
)
print(" - WSTUN zombie process cleaned.")
except Exception as exc:
print(" - [hunter] Error cleaning wstun " +
@ -464,7 +496,7 @@ class ServiceManager(Module.Module):
except Exception:
pass
break
# break
if not wstun_found:
message = "Tunnel killed by LR"
@ -479,9 +511,13 @@ class ServiceManager(Module.Module):
# Clean zombie processes (no wstun)
try:
os.waitpid(-1, os.WNOHANG)
LOG.debug(
"[_zombie_hunter] Generic zombie " +
"process cleaned."
)
print(" - Generic zombie process cleaned.")
except Exception as exc:
print(" - [hunter] Error cleaning "
print(" - [_zombie_hunter] Error cleaning "
"generic zombie process: " + str(exc))
# LOG.debug("[WSTUN-RESTORE] --> " + str(message))
@ -613,7 +649,14 @@ class ServiceManager(Module.Module):
)
)
os.kill(wstun.pid, signal.SIGKILL)
try:
os.kill(wstun.pid, signal.SIGKILL)
LOG.debug(
" - [_wstunMon] WSTUN process " +
"[" + str(wstun.pid) + "] killed")
except OSError as err:
LOG.warning(" - [_wstunMon] WSTUN killing error: "
+ str(err))
_method_name.__name__ = "process_{}".format(method)
setattr(cls, _method_name.__name__, _method_name)
@ -951,6 +994,22 @@ class ServiceManager(Module.Module):
lightningrod.zombie_alert = False
os.kill(service_pid, signal.SIGKILL)
LOG.info(" - [ServiceDisable] WSTUN process " +
"[" + str(service_pid) + "] killed")
try:
os.waitpid(-1, os.WNOHANG)
LOG.debug(
" - [ServiceDisable] WSTUN zombie " +
"process cleaned."
)
except Exception as exc:
print(
" - [ServiceDisable] " +
"Error cleaning old " +
"wstun zombie process: " +
str(exc)
)
message = "Cloud service '" \
+ str(service_name) + "' tunnel disabled."
@ -1054,6 +1113,21 @@ class ServiceManager(Module.Module):
LOG.info(" - service '" + service_name
+ "' with PID " + str(service_pid)
+ " was killed.")
try:
os.waitpid(-1, os.WNOHANG)
LOG.debug(
" - [ServiceRestore] WSTUN zombie " +
"process cleaned."
)
except Exception as exc:
print(
" - [ServiceRestore] " +
"Error cleaning old " +
"wstun zombie process: " +
str(exc)
)
except OSError:
LOG.warning(" - WSTUN process already killed: "
"creating new one...")

View File

@ -84,6 +84,7 @@ $(function(){
<div class="form-group">
<form method="post">
<div class="form-group">
<label for="urlwagent">Registration Agent URL:</label>
<input class="form-control" name="urlwagent" id="urlwagent" value="{{ urlwagent }}" required placeholder="ws(s)://<WAGENT-ADDRESS>:<WAGENT-PORT>">
@ -92,7 +93,14 @@ $(function(){
<label for="code">Registration Code:</label>
<input class="form-control" name="code" id="code" value="{{ code }}" required>
</div>
<div class="form-group">
<label for="hostname">Device hostname:</label>
<input class="form-control" name="hostname" id="hostname" value="{{ hostname }}" >
</div>
<input class="btn btn-success" type="submit" value="CONFIGURE" name="reg_btn">
</form>
</div>

View File

@ -39,8 +39,22 @@
<form method="get" action="/config">
<tr>
<td style="width:30%"> <input class="btn btn-primary btn-block" type="submit" value="LR restart" name="lr_restart_btn"> </td>
<td> Restart Lightning-rod. </td>
<td style="width:30%"> <label for="hostname">Restart Lightning-rod.</label> </td>
<td style="width:30%"> </td>
<td style="width:30%"> <input class="btn btn-primary btn-block" type="submit" value="Restart" name="lr_restart_btn"> </td>
</tr>
</form>
<form method="post" action="/config">
<tr>
<td style="width:30%"> <label for="hostname">Change device hostname:</label> </td>
<td style="width:30%"> <input class="form-control" name="hostname" id="hostname" value="{{ hostname }}" required> </td>
<td style="width:30%"> <input class="btn btn-primary btn-block" type="submit" value="Change" name="change_hostname"> </td>
</tr>
</form>

View File

@ -13,10 +13,9 @@ classifier =
License :: OSI Approved :: Apache Software License
Operating System :: POSIX :: Linux
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
[files]
packages =

View File

@ -1,6 +1,6 @@
[tox]
minversion = 2.3.1
envlist = py35,pep8
envlist = py36,pep8
skipsdist = True
[testenv]

View File

@ -1,13 +1,18 @@
FROM ubuntu:bionic
ENV DEBIAN_FRONTEND=noninteractive
RUN chmod -R 777 /tmp/
RUN apt-get update && apt-get install -y \
socat dsniff git ntpdate python build-essential vim lsof gdb screen python3 python3-setuptools python3-pip npm net-tools
software-properties-common socat dsniff git ntpdate python build-essential vim lsof gdb screen python3 python3-setuptools python3-pip npm net-tools
RUN add-apt-repository ppa:certbot/certbot
ENV TZ 'Europe/Rome'
ENV DEBIAN_FRONTEND=noninteractive
RUN echo $TZ > /etc/timezone && apt-get update && apt-get install -y tzdata && rm -f /etc/localtime && ln -nfs /usr/share/zoneinfo/$TZ /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
RUN apt-get install -y nginx python-certbot-nginx
RUN apt-get update && apt-get install -y nginx python-certbot-nginx
RUN sed -i 's/# server_names_hash_bucket_size 64;/server_names_hash_bucket_size 64;/g' /etc/nginx/nginx.conf
RUN rm -rf /var/lib/apt/lists/*

View File

@ -1,15 +1,22 @@
FROM ubuntu:bionic
RUN apt-get update && apt-get install -y \
socat dsniff git ntpdate python build-essential vim lsof gdb screen python3 python3-setuptools python3-pip npm net-tools
ENV DEBIAN_FRONTEND=noninteractive
RUN chmod -R 777 /tmp/
RUN apt-get update && apt-get install -y \
software-properties-common socat dsniff git ntpdate python build-essential lsof gdb screen python3 python3-setuptools python3-pip npm net-tools
RUN add-apt-repository ppa:certbot/certbot
ENV TZ 'Europe/Rome'
ENV DEBIAN_FRONTEND=noninteractive
RUN echo $TZ > /etc/timezone && apt-get update && apt-get install -y tzdata && rm -f /etc/localtime && ln -nfs /usr/share/zoneinfo/$TZ /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
RUN apt-get install -y nginx python-certbot-nginx
RUN apt-get update && apt-get install -y nginx python-certbot-nginx
RUN sed -i 's/# server_names_hash_bucket_size 64;/server_names_hash_bucket_size 64;/g' /etc/nginx/nginx.conf
#RUN apt-get install -y certbot
RUN rm -rf /var/lib/apt/lists/*
RUN npm install -g --unsafe @mdslab/wstun@1.0.10 && npm cache --force clean