mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Merge branch 'master' into 3.0
# Conflicts: # .github/workflows/testing.yml # gns3server/compute/builtin/nodes/nat.py # gns3server/compute/qemu/__init__.py # gns3server/controller/link.py # gns3server/utils/asyncio/embed_shell.py # gns3server/utils/asyncio/raw_command_server.py # gns3server/utils/asyncio/telnet_server.py # gns3server/version.py # gns3server/web/web_server.py
This commit is contained in:
commit
afdda427d2
11
CHANGELOG
11
CHANGELOG
@ -1,5 +1,16 @@
|
||||
# Change Log
|
||||
|
||||
## 2.2.24 25/08/2021
|
||||
|
||||
* Release web UI 2.2.24
|
||||
* Fix issue when searching for image with relative path. Fixes #1925
|
||||
* Fix wrong error when NAT interface is not allowed. Fixes #1943
|
||||
* Fix incorrect Qemu binary selected when importing template. Fixes https://github.com/GNS3/gns3-gui/issues/3216
|
||||
* Fix error when updating a link style. Fixes https://github.com/GNS3/gns3-gui/issues/2461
|
||||
* Some fixes for early support for Python3.10 The loop parameter has been removed from most of asyncio‘s high-level API following deprecation in Python 3.8.
|
||||
* Early support for Python3.10 Fixes #1940
|
||||
* Bump pywin32 from 300 to 301
|
||||
|
||||
## 2.2.23 05/08/2021
|
||||
|
||||
* Release web UI 2.2.23
|
||||
|
@ -30,8 +30,7 @@
|
||||
"version": "1.3.0-rc5",
|
||||
"md5sum": "dd704f59afc0fccdf601cc750bf2c438",
|
||||
"filesize": 361955328,
|
||||
"download_url": "https://www.b-ehlers.de/GNS3/images/",
|
||||
"direct_download_url": "https://www.b-ehlers.de/GNS3/images/vyos-1.3.0-rc5-amd64.qcow2"
|
||||
"direct_download_url": "https://www.mediafire.com/file/taspgxh4vj0a4j1/vyos-1.3.0-rc5-amd64.qcow2/file"
|
||||
},
|
||||
{
|
||||
"filename": "vyos-1.2.8-amd64.iso",
|
||||
|
@ -475,8 +475,7 @@ class BaseManager:
|
||||
|
||||
for root, dirs, files in os.walk(directory):
|
||||
for file in files:
|
||||
# If filename is the same
|
||||
if s[1] == file and (s[0] == '' or os.path.basename(s[0]) == os.path.basename(root)):
|
||||
if s[1] == file and (s[0] == '' or root == os.path.join(directory, s[0])):
|
||||
path = os.path.normpath(os.path.join(root, s[1]))
|
||||
if os.path.exists(path):
|
||||
return path
|
||||
|
@ -36,10 +36,16 @@ class Nat(Cloud):
|
||||
|
||||
def __init__(self, name, node_id, project, manager, ports=None):
|
||||
|
||||
allowed_interfaces = Config.instance().get_section_config("Server").get("allowed_interfaces", None)
|
||||
if allowed_interfaces:
|
||||
allowed_interfaces = allowed_interfaces.split(',')
|
||||
if sys.platform.startswith("linux"):
|
||||
nat_interface = Config.instance().settings.Server.default_nat_interface
|
||||
if not nat_interface:
|
||||
nat_interface = "virbr0"
|
||||
if allowed_interfaces and nat_interface not in allowed_interfaces:
|
||||
raise NodeError("NAT interface {} is not allowed be used on this server. "
|
||||
"Please check the server configuration file.".format(nat_interface))
|
||||
if nat_interface not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]:
|
||||
raise NodeError(f"NAT interface {nat_interface} is missing, please install libvirt")
|
||||
interface = nat_interface
|
||||
@ -47,6 +53,9 @@ class Nat(Cloud):
|
||||
nat_interface = Config.instance().settings.Server.default_nat_interface
|
||||
if not nat_interface:
|
||||
nat_interface = "vmnet8"
|
||||
if allowed_interfaces and nat_interface not in allowed_interfaces:
|
||||
raise NodeError("NAT interface {} is not allowed be used on this server. "
|
||||
"Please check the server configuration file.".format(nat_interface))
|
||||
interfaces = list(
|
||||
filter(
|
||||
lambda x: nat_interface in x.lower(),
|
||||
|
@ -152,8 +152,6 @@ class Qemu(BaseManager):
|
||||
log.debug(f"Searching for Qemu binaries in '{path}'")
|
||||
try:
|
||||
for f in os.listdir(path):
|
||||
if f.endswith("-spice"):
|
||||
continue
|
||||
if (
|
||||
(f.startswith("qemu-system") or f.startswith("qemu-kvm") or f == "qemu" or f == "qemu.exe")
|
||||
and os.access(os.path.join(path, f), os.X_OK)
|
||||
|
@ -174,7 +174,6 @@ class Link:
|
||||
async def update_link_style(self, link_style):
|
||||
if link_style != self._link_style:
|
||||
self._link_style = link_style
|
||||
await self.update()
|
||||
self._project.emit_notification("link.updated", self.asdict())
|
||||
self._project.dump()
|
||||
|
||||
|
@ -59,7 +59,7 @@ class CrashReport:
|
||||
Report crash to a third party service
|
||||
"""
|
||||
|
||||
DSN = "https://aefc1e0e41e94957936f8773071aebf9:056b5247d4854b81ac9162d9ccc5a503@o19455.ingest.sentry.io/38482"
|
||||
DSN = "https://95f189bae52543e38be226cc1de2c8f3:e06825958e234a3e9ae5a81eaa21993d@o19455.ingest.sentry.io/38482"
|
||||
_instance = None
|
||||
|
||||
def __init__(self):
|
||||
|
File diff suppressed because one or more lines are too long
1
gns3server/static/web-ui/26.b66762bd9b75f566201f.js
Normal file
1
gns3server/static/web-ui/26.b66762bd9b75f566201f.js
Normal file
File diff suppressed because one or more lines are too long
@ -2621,13 +2621,25 @@ uuid
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2010-2020 Robert Kieffer and other contributors
|
||||
Copyright (c) 2010-2016 Robert Kieffer and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
xterm
|
||||
|
@ -1,6 +1,9 @@
|
||||
GNS3 WebUI is web implementation of user interface for GNS3 software.
|
||||
|
||||
Current version: 2.2.22
|
||||
Current version: 2.2.24
|
||||
|
||||
Bug Fixes & enhancements
|
||||
- security fixes
|
||||
|
||||
Current version: 2020.4.0-beta.1
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
1
gns3server/static/web-ui/main.2508108fae5a3eec0c74.js
Normal file
1
gns3server/static/web-ui/main.2508108fae5a3eec0c74.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
!function(){"use strict";var e,t,r,n,o={},u={};function i(e){var t=u[e];if(void 0!==t)return t.exports;var r=u[e]={id:e,loaded:!1,exports:{}};return o[e](r,r.exports,i),r.loaded=!0,r.exports}i.m=o,e=[],i.O=function(t,r,n,o){if(!r){var u=1/0;for(d=0;d<e.length;d++){r=e[d][0],n=e[d][1],o=e[d][2];for(var a=!0,c=0;c<r.length;c++)(!1&o||u>=o)&&Object.keys(i.O).every(function(e){return i.O[e](r[c])})?r.splice(c--,1):(a=!1,o<u&&(u=o));a&&(e.splice(d--,1),t=n())}return t}o=o||0;for(var d=e.length;d>0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[r,n,o]},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,{a:t}),t},i.d=function(e,t){for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.f={},i.e=function(e){return Promise.all(Object.keys(i.f).reduce(function(t,r){return i.f[r](e,t),t},[]))},i.u=function(e){return e+".a7470e50128ddf7860c4.js"},i.miniCssF=function(e){return"styles.c514ad565d1e615b86db.css"},i.hmd=function(e){return(e=Object.create(e)).children||(e.children=[]),Object.defineProperty(e,"exports",{enumerable:!0,set:function(){throw new Error("ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: "+e.id)}}),e},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t={},r="gns3-web-ui:",i.l=function(e,n,o,u){if(t[e])t[e].push(n);else{var a,c;if(void 0!==o)for(var d=document.getElementsByTagName("script"),f=0;f<d.length;f++){var s=d[f];if(s.getAttribute("src")==e||s.getAttribute("data-webpack")==r+o){a=s;break}}a||(c=!0,(a=document.createElement("script")).charset="utf-8",a.timeout=120,i.nc&&a.setAttribute("nonce",i.nc),a.setAttribute("data-webpack",r+o),a.src=i.tu(e)),t[e]=[n];var l=function(r,n){a.onerror=a.onload=null,clearTimeout(p);var o=t[e];if(delete t[e],a.parentNode&&a.parentNode.removeChild(a),o&&o.forEach(function(e){return e(n)}),r)return r(n)},p=setTimeout(l.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=l.bind(null,a.onerror),a.onload=l.bind(null,a.onload),c&&document.head.appendChild(a)}},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.tu=function(e){return void 0===n&&(n={createScriptURL:function(e){return e}},"undefined"!=typeof trustedTypes&&trustedTypes.createPolicy&&(n=trustedTypes.createPolicy("angular#bundler",n))),n.createScriptURL(e)},i.p="",function(){var e={666:0};i.f.j=function(t,r){var n=i.o(e,t)?e[t]:void 0;if(0!==n)if(n)r.push(n[2]);else if(666!=t){var o=new Promise(function(r,o){n=e[t]=[r,o]});r.push(n[2]=o);var u=i.p+i.u(t),a=new Error;i.l(u,function(r){if(i.o(e,t)&&(0!==(n=e[t])&&(e[t]=void 0),n)){var o=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;a.message="Loading chunk "+t+" failed.\n("+o+": "+u+")",a.name="ChunkLoadError",a.type=o,a.request=u,n[1](a)}},"chunk-"+t,t)}else e[t]=0},i.O.j=function(t){return 0===e[t]};var t=function(t,r){var n,o,u=r[0],a=r[1],c=r[2],d=0;for(n in a)i.o(a,n)&&(i.m[n]=a[n]);if(c)var f=c(i);for(t&&t(r);d<u.length;d++)i.o(e,o=u[d])&&e[o]&&e[o][0](),e[u[d]]=0;return i.O(f)},r=self.webpackChunkgns3_web_ui=self.webpackChunkgns3_web_ui||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))}()}();
|
1
gns3server/static/web-ui/runtime.da4235648c8c34b088fc.js
Normal file
1
gns3server/static/web-ui/runtime.da4235648c8c34b088fc.js
Normal file
@ -0,0 +1 @@
|
||||
!function(){"use strict";var e,v={},g={};function n(e){var u=g[e];if(void 0!==u)return u.exports;var t=g[e]={id:e,loaded:!1,exports:{}};return v[e](t,t.exports,n),t.loaded=!0,t.exports}n.m=v,e=[],n.O=function(u,t,a,o){if(!t){var r=1/0;for(i=0;i<e.length;i++){t=e[i][0],a=e[i][1],o=e[i][2];for(var l=!0,f=0;f<t.length;f++)(!1&o||r>=o)&&Object.keys(n.O).every(function(b){return n.O[b](t[f])})?t.splice(f--,1):(l=!1,o<r&&(r=o));if(l){e.splice(i--,1);var s=a();void 0!==s&&(u=s)}}return u}o=o||0;for(var i=e.length;i>0&&e[i-1][2]>o;i--)e[i]=e[i-1];e[i]=[t,a,o]},n.n=function(e){var u=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(u,{a:u}),u},n.d=function(e,u){for(var t in u)n.o(u,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:u[t]})},n.f={},n.e=function(e){return Promise.all(Object.keys(n.f).reduce(function(u,t){return n.f[t](e,u),u},[]))},n.u=function(e){return e+".b66762bd9b75f566201f.js"},n.miniCssF=function(e){return"styles.f77f6cd675ecc98f0177.css"},n.hmd=function(e){return(e=Object.create(e)).children||(e.children=[]),Object.defineProperty(e,"exports",{enumerable:!0,set:function(){throw new Error("ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: "+e.id)}}),e},n.o=function(e,u){return Object.prototype.hasOwnProperty.call(e,u)},function(){var e={},u="gns3-web-ui:";n.l=function(t,a,o,i){if(e[t])e[t].push(a);else{var r,l;if(void 0!==o)for(var f=document.getElementsByTagName("script"),s=0;s<f.length;s++){var c=f[s];if(c.getAttribute("src")==t||c.getAttribute("data-webpack")==u+o){r=c;break}}r||(l=!0,(r=document.createElement("script")).charset="utf-8",r.timeout=120,n.nc&&r.setAttribute("nonce",n.nc),r.setAttribute("data-webpack",u+o),r.src=n.tu(t)),e[t]=[a];var d=function(h,b){r.onerror=r.onload=null,clearTimeout(p);var _=e[t];if(delete e[t],r.parentNode&&r.parentNode.removeChild(r),_&&_.forEach(function(m){return m(b)}),h)return h(b)},p=setTimeout(d.bind(null,void 0,{type:"timeout",target:r}),12e4);r.onerror=d.bind(null,r.onerror),r.onload=d.bind(null,r.onload),l&&document.head.appendChild(r)}}}(),n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},function(){var e;n.tu=function(u){return void 0===e&&(e={createScriptURL:function(t){return t}},"undefined"!=typeof trustedTypes&&trustedTypes.createPolicy&&(e=trustedTypes.createPolicy("angular#bundler",e))),e.createScriptURL(u)}}(),n.p="",function(){var e={666:0};n.f.j=function(a,o){var i=n.o(e,a)?e[a]:void 0;if(0!==i)if(i)o.push(i[2]);else if(666!=a){var r=new Promise(function(c,d){i=e[a]=[c,d]});o.push(i[2]=r);var l=n.p+n.u(a),f=new Error;n.l(l,function(c){if(n.o(e,a)&&(0!==(i=e[a])&&(e[a]=void 0),i)){var d=c&&("load"===c.type?"missing":c.type),p=c&&c.target&&c.target.src;f.message="Loading chunk "+a+" failed.\n("+d+": "+p+")",f.name="ChunkLoadError",f.type=d,f.request=p,i[1](f)}},"chunk-"+a,a)}else e[a]=0},n.O.j=function(a){return 0===e[a]};var u=function(a,o){var f,s,i=o[0],r=o[1],l=o[2],c=0;for(f in r)n.o(r,f)&&(n.m[f]=r[f]);if(l)var d=l(n);for(a&&a(o);c<i.length;c++)n.o(e,s=i[c])&&e[s]&&e[s][0](),e[i[c]]=0;return n.O(d)},t=self.webpackChunkgns3_web_ui=self.webpackChunkgns3_web_ui||[];t.forEach(u.bind(null,0)),t.push=u.bind(null,t.push.bind(t))}()}();
|
File diff suppressed because one or more lines are too long
11
gns3server/static/web-ui/styles.f77f6cd675ecc98f0177.css
Normal file
11
gns3server/static/web-ui/styles.f77f6cd675ecc98f0177.css
Normal file
File diff suppressed because one or more lines are too long
@ -357,7 +357,7 @@ if __name__ == "__main__":
|
||||
# Demo using telnet
|
||||
shell = Demo(welcome_message="Welcome!\n")
|
||||
server = create_telnet_shell(shell, loop=loop)
|
||||
coro = asyncio.start_server(server.run, "127.0.0.1", 4444, loop=loop)
|
||||
coro = asyncio.start_server(server.run, "127.0.0.1", 4444)
|
||||
s = loop.run_until_complete(coro)
|
||||
try:
|
||||
loop.run_forever()
|
||||
|
@ -127,7 +127,7 @@ if __name__ == "__main__":
|
||||
)
|
||||
],
|
||||
)
|
||||
coro = asyncio.start_server(server.run, "0.0.0.0", 4444, loop=loop)
|
||||
coro = asyncio.start_server(server.run, "0.0.0.0", 4444)
|
||||
s = loop.run_until_complete(coro)
|
||||
|
||||
try:
|
||||
|
@ -420,7 +420,7 @@ if __name__ == "__main__":
|
||||
)
|
||||
server = AsyncioTelnetServer(reader=process.stdout, writer=process.stdin, binary=False, echo=False)
|
||||
|
||||
coro = asyncio.start_server(server.run, "127.0.0.1", 4444, loop=loop)
|
||||
coro = asyncio.start_server(server.run, "127.0.0.1", 4444)
|
||||
s = loop.run_until_complete(coro)
|
||||
|
||||
try:
|
||||
|
344
gns3server/web/web_server.py
Normal file
344
gns3server/web/web_server.py
Normal file
@ -0,0 +1,344 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2015 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
Set up and run the server.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import signal
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import aiohttp_cors
|
||||
import functools
|
||||
import time
|
||||
import atexit
|
||||
import weakref
|
||||
|
||||
# Import encoding now, to avoid implicit import later.
|
||||
# Implicit import within threads may cause LookupError when standard library is in a ZIP
|
||||
import encodings.idna
|
||||
|
||||
from .route import Route
|
||||
from ..config import Config
|
||||
from ..compute import MODULES
|
||||
from ..compute.port_manager import PortManager
|
||||
from ..compute.qemu import Qemu
|
||||
from ..controller import Controller
|
||||
|
||||
# do not delete this import
|
||||
import gns3server.handlers
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
if not (aiohttp.__version__.startswith("3.")):
|
||||
raise RuntimeError("aiohttp 3.x is required to run the GNS3 server")
|
||||
|
||||
|
||||
class WebServer:
|
||||
|
||||
def __init__(self, host, port):
|
||||
|
||||
self._host = host
|
||||
self._port = port
|
||||
self._loop = None
|
||||
self._handler = None
|
||||
self._server = None
|
||||
self._app = None
|
||||
self._start_time = time.time()
|
||||
self._running = False
|
||||
self._closing = False
|
||||
self._ssl_context = None
|
||||
|
||||
@staticmethod
|
||||
def instance(host=None, port=None):
|
||||
"""
|
||||
Singleton to return only one instance of Server.
|
||||
|
||||
:returns: instance of Server
|
||||
"""
|
||||
|
||||
if not hasattr(WebServer, "_instance") or WebServer._instance is None:
|
||||
assert host is not None
|
||||
assert port is not None
|
||||
WebServer._instance = WebServer(host, port)
|
||||
return WebServer._instance
|
||||
|
||||
def _run_application(self, handler, ssl_context=None):
|
||||
try:
|
||||
srv = self._loop.create_server(handler, self._host, self._port, ssl=ssl_context)
|
||||
self._server, startup_res = self._loop.run_until_complete(asyncio.gather(srv, self._app.startup(), loop=self._loop))
|
||||
except (RuntimeError, OSError, asyncio.CancelledError) as e:
|
||||
log.critical("Could not start the server: {}".format(e))
|
||||
return False
|
||||
return True
|
||||
|
||||
async def reload_server(self):
|
||||
"""
|
||||
Reload the server.
|
||||
"""
|
||||
|
||||
await Controller.instance().reload()
|
||||
|
||||
async def shutdown_server(self):
|
||||
"""
|
||||
Cleanly shutdown the server.
|
||||
"""
|
||||
|
||||
if not self._closing:
|
||||
self._closing = True
|
||||
else:
|
||||
log.warning("Close is already in progress")
|
||||
return
|
||||
|
||||
# close websocket connections
|
||||
websocket_connections = set(self._app['websockets'])
|
||||
if websocket_connections:
|
||||
log.info("Closing {} websocket connections...".format(len(websocket_connections)))
|
||||
for ws in websocket_connections:
|
||||
await ws.close(code=aiohttp.WSCloseCode.GOING_AWAY, message='Server shutdown')
|
||||
|
||||
if self._server:
|
||||
self._server.close()
|
||||
await self._server.wait_closed()
|
||||
if self._app:
|
||||
await self._app.shutdown()
|
||||
if self._handler:
|
||||
await self._handler.shutdown(2) # Parameter is timeout
|
||||
if self._app:
|
||||
await self._app.cleanup()
|
||||
|
||||
await Controller.instance().stop()
|
||||
|
||||
for module in MODULES:
|
||||
log.debug("Unloading module {}".format(module.__name__))
|
||||
m = module.instance()
|
||||
await m.unload()
|
||||
|
||||
if PortManager.instance().tcp_ports:
|
||||
log.warning("TCP ports are still used {}".format(PortManager.instance().tcp_ports))
|
||||
|
||||
if PortManager.instance().udp_ports:
|
||||
log.warning("UDP ports are still used {}".format(PortManager.instance().udp_ports))
|
||||
|
||||
try:
|
||||
tasks = asyncio.all_tasks()
|
||||
except AttributeError:
|
||||
tasks = asyncio.Task.all_tasks()
|
||||
|
||||
for task in tasks:
|
||||
task.cancel()
|
||||
try:
|
||||
await asyncio.wait_for(task, 1)
|
||||
except BaseException:
|
||||
pass
|
||||
|
||||
self._loop.stop()
|
||||
|
||||
def ssl_context(self):
|
||||
"""
|
||||
Returns the SSL context for the server.
|
||||
"""
|
||||
|
||||
return self._ssl_context
|
||||
|
||||
def _signal_handling(self):
|
||||
|
||||
def signal_handler(signame, *args):
|
||||
|
||||
try:
|
||||
if signame == "SIGHUP":
|
||||
log.info("Server has got signal {}, reloading...".format(signame))
|
||||
asyncio.ensure_future(self.reload_server())
|
||||
else:
|
||||
log.warning("Server has got signal {}, exiting...".format(signame))
|
||||
asyncio.ensure_future(self.shutdown_server())
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
|
||||
signals = ["SIGTERM", "SIGINT"]
|
||||
if sys.platform.startswith("win"):
|
||||
signals.extend(["SIGBREAK"])
|
||||
else:
|
||||
signals.extend(["SIGHUP", "SIGQUIT"])
|
||||
|
||||
for signal_name in signals:
|
||||
callback = functools.partial(signal_handler, signal_name)
|
||||
if sys.platform.startswith("win"):
|
||||
# add_signal_handler() is not yet supported on Windows
|
||||
signal.signal(getattr(signal, signal_name), callback)
|
||||
else:
|
||||
self._loop.add_signal_handler(getattr(signal, signal_name), callback)
|
||||
|
||||
def _create_ssl_context(self, server_config):
|
||||
|
||||
import ssl
|
||||
ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
||||
certfile = server_config["certfile"]
|
||||
certkey = server_config["certkey"]
|
||||
try:
|
||||
ssl_context.load_cert_chain(certfile, certkey)
|
||||
except FileNotFoundError:
|
||||
log.critical("Could not find the SSL certfile or certkey")
|
||||
raise SystemExit
|
||||
except ssl.SSLError as e:
|
||||
log.critical("SSL error: {}".format(e))
|
||||
raise SystemExit
|
||||
log.info("SSL is enabled")
|
||||
return ssl_context
|
||||
|
||||
async def start_shell(self):
|
||||
|
||||
log.error("The embedded shell has been deactivated in this version of GNS3")
|
||||
return
|
||||
try:
|
||||
from ptpython.repl import embed
|
||||
except ImportError:
|
||||
log.error("Unable to start a shell: the ptpython module must be installed!")
|
||||
return
|
||||
await embed(globals(), locals(), return_asyncio_coroutine=True, patch_stdout=True, history_filename=".gns3_shell_history")
|
||||
|
||||
def _exit_handling(self):
|
||||
"""
|
||||
Makes sure the asyncio loop is closed.
|
||||
"""
|
||||
|
||||
def close_asyncio_loop():
|
||||
loop = None
|
||||
try:
|
||||
loop = asyncio.get_event_loop()
|
||||
except AttributeError:
|
||||
pass
|
||||
if loop is not None:
|
||||
loop.close()
|
||||
|
||||
atexit.register(close_asyncio_loop)
|
||||
|
||||
async def _on_startup(self, *args):
|
||||
"""
|
||||
Called when the HTTP server start
|
||||
"""
|
||||
|
||||
await Controller.instance().start()
|
||||
# Because with a large image collection
|
||||
# without md5sum already computed we start the
|
||||
# computing with server start
|
||||
asyncio.ensure_future(Qemu.instance().list_images())
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Starts the server.
|
||||
"""
|
||||
|
||||
server_logger = logging.getLogger('aiohttp.server')
|
||||
# In debug mode we don't use the standard request log but a more complete in response.py
|
||||
if log.getEffectiveLevel() == logging.DEBUG:
|
||||
server_logger.setLevel(logging.CRITICAL)
|
||||
|
||||
logger = logging.getLogger("asyncio")
|
||||
logger.setLevel(logging.ERROR)
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
loop = asyncio.get_event_loop()
|
||||
# Add a periodic callback to give a chance to process signals on Windows
|
||||
# because asyncio.add_signal_handler() is not supported yet on that platform
|
||||
# otherwise the loop runs outside of signal module's ability to trap signals.
|
||||
|
||||
def wakeup():
|
||||
loop.call_later(0.5, wakeup)
|
||||
loop.call_later(0.5, wakeup)
|
||||
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
|
||||
self._ssl_context = None
|
||||
if server_config.getboolean("ssl"):
|
||||
if sys.platform.startswith("win"):
|
||||
log.critical("SSL mode is not supported on Windows")
|
||||
raise SystemExit
|
||||
self._ssl_context = self._create_ssl_context(server_config)
|
||||
|
||||
self._loop = asyncio.get_event_loop()
|
||||
|
||||
if log.getEffectiveLevel() == logging.DEBUG:
|
||||
# On debug version we enable info that
|
||||
# coroutine is not called in a way await/await
|
||||
self._loop.set_debug(True)
|
||||
|
||||
for key, val in os.environ.items():
|
||||
log.debug("ENV %s=%s", key, val)
|
||||
|
||||
self._app = aiohttp.web.Application()
|
||||
|
||||
# Keep a list of active websocket connections
|
||||
self._app['websockets'] = weakref.WeakSet()
|
||||
|
||||
# Background task started with the server
|
||||
self._app.on_startup.append(self._on_startup)
|
||||
|
||||
resource_options = aiohttp_cors.ResourceOptions(expose_headers="*", allow_headers="*", max_age=0)
|
||||
|
||||
# Allow CORS for this domains
|
||||
cors = aiohttp_cors.setup(self._app, defaults={
|
||||
# Default web server for web gui dev
|
||||
"http://127.0.0.1:8080": resource_options,
|
||||
"http://localhost:8080": resource_options,
|
||||
"http://127.0.0.1:4200": resource_options,
|
||||
"http://localhost:4200": resource_options,
|
||||
"http://gns3.github.io": resource_options,
|
||||
"https://gns3.github.io": resource_options
|
||||
})
|
||||
|
||||
PortManager.instance().console_host = self._host
|
||||
|
||||
for method, route, handler in Route.get_routes():
|
||||
log.debug("Adding route: {} {}".format(method, route))
|
||||
cors.add(self._app.router.add_route(method, route, handler))
|
||||
|
||||
for module in MODULES:
|
||||
log.debug("Loading module {}".format(module.__name__))
|
||||
m = module.instance()
|
||||
m.port_manager = PortManager.instance()
|
||||
|
||||
log.info("Starting server on {}:{}".format(self._host, self._port))
|
||||
|
||||
self._handler = self._app.make_handler()
|
||||
if self._run_application(self._handler, self._ssl_context) is False:
|
||||
self._loop.stop()
|
||||
sys.exit(1)
|
||||
|
||||
self._signal_handling()
|
||||
self._exit_handling()
|
||||
|
||||
if server_config.getboolean("shell"):
|
||||
asyncio.ensure_future(self.start_shell())
|
||||
|
||||
try:
|
||||
self._loop.run_forever()
|
||||
except TypeError as e:
|
||||
# This is to ignore an asyncio.windows_events exception
|
||||
# on Windows when the process gets the SIGBREAK signal
|
||||
# TypeError: async() takes 1 positional argument but 3 were given
|
||||
log.warning("TypeError exception in the loop {}".format(e))
|
||||
finally:
|
||||
if self._loop.is_running():
|
||||
try:
|
||||
self._loop.run_until_complete(self.shutdown_server())
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user