Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web] refactor OTBR-WEB #537

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .travis/check-docker
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,19 @@ main()

readonly OTBR_DOCKER_PID=$(docker run --rm -dit \
--sysctl "net.ipv6.conf.all.disable_ipv6=0 net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1" \
--privileged -p 8080:80 --dns=127.0.0.1 --volume "$DOCKER_PTY":/dev/ttyUSB0 otbr)
--privileged -p 8081:8081 --dns=127.0.0.1 --volume "$DOCKER_PTY":/dev/ttyUSB0 otbr)
sleep 10
sudo lsof -i :8080
sudo lsof -i :8081

local -r OTBR_WEB_URL="http://127.0.0.1:8080"
local -r OTBR_REST_URL="http://127.0.0.1:8081"
local -r OT_MASTER_KEY=00112233445566778899aabbccddeeff
local -r OT_XPANID=0011223344556677
local -r OT_PANID=0xface
local -r OT_AGENT_PASSPHRASE=123456
local -r OT_CHANNEL=12
local -r OT_NETWORK_NAME=OpenThreadDocker

curl "${OTBR_WEB_URL}"/index.html | grep 'What is OpenThread'
curl --header "Content-Type: application/json" --request POST --data "{\"masterKey\":\"${OT_MASTER_KEY}\",\"prefix\":\"fd11:22::\",\"defaultRoute\":true,\"extPanId\":\"${OT_XPANID}\",\"panId\":\"${OT_PANID}\",\"passphrase\":\"${OT_AGENT_PASSPHRASE}\",\"channel\":${OT_CHANNEL},\"networkName\":\"${OT_NETWORK_NAME}\"}" "${OTBR_WEB_URL}"/form_network | grep "success"
curl --header "Content-Type: application/json" --request POST --data "{\"masterKey\":\"${OT_MASTER_KEY}\",\"prefix\":\"fd11:22::\",\"defaultRoute\":true,\"extPanId\":\"${OT_XPANID}\",\"panId\":\"${OT_PANID}\",\"passphrase\":\"${OT_AGENT_PASSPHRASE}\",\"channel\":${OT_CHANNEL},\"networkName\":\"${OT_NETWORK_NAME}\"}" "${OTBR_REST_URL}"/v1/networks | grep "${OT_PANID}"
}

main "$@"
13 changes: 1 addition & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ option(OTBR_BACKBONE_ROUTER "Build Backbone Router" OFF)
option(OTBR_DBUS "Build DBus support" OFF)
option(OTBR_OPENWRT "Build OpenWrt support" OFF)
option(OTBR_UNSECURE_JOIN "Enable unsecure joining" OFF)
option(OTBR_WEB "Build Web GUI" OFF)
option(OTBR_REST "Build Rest Server" OFF)


Expand Down Expand Up @@ -115,16 +114,6 @@ if(OTBR_REST)
)
endif()

if(OTBR_WEB)
pkg_check_modules(JSONCPP jsoncpp REQUIRED)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED
COMPONENTS filesystem system)
set(OTBR_WEB_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/otbr-web)
endif()

if(OTBR_OPENWRT)
target_compile_definitions(otbr-config INTERFACE
OTBR_ENABLE_OPENWRT=1
Expand All @@ -147,7 +136,7 @@ if(SYSTEMD_FOUND)
endif()


add_subdirectory(third_party EXCLUDE_FROM_ALL)
add_subdirectory(third_party)
add_subdirectory(src)
add_subdirectory(tools)

Expand Down
1 change: 0 additions & 1 deletion etc/docker/docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ sed -i "s/^prefix.*$/prefix $NAT64_PREFIX/" /etc/tayga.conf
sed -i "s/dns64.*$/dns64 $NAT64_PREFIX {};/" /etc/bind/named.conf.options

echo "OTBR_AGENT_OPTS=\"-I $TUN_INTERFACE_NAME $BACKBONE_INTERFACE_ARG -d7 $RADIO_URL\"" >/etc/default/otbr-agent
echo "OTBR_WEB_OPTS=\"-I $TUN_INTERFACE_NAME -d7 -p 80\"" >/etc/default/otbr-web

/app/script/server

Expand Down
47 changes: 47 additions & 0 deletions etc/rest/otbr-nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright (c) 2020, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Description:
# The Nginx configuration file for OTBR web.
#

server {
listen 80;
listen [::]:80;
server_name _;

location / {
root /var/otbr/frontend;
index index.html;
}
location /v1/ {
proxy_pass http://0.0.0.0:8081;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allows customize port number?

proxy_set_header Host $proxy_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}
48 changes: 48 additions & 0 deletions script/_nginx_config_install
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
#
# Copyright (c) 2020, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

readonly NGINX_CONF_DIR=/etc/nginx

nginx_config_install()
{
if command -v nginx; then
sudo cp etc/rest/otbr-nginx.conf "${NGINX_CONF_DIR}"/sites-available/
sudo rm -rf "${NGINX_CONF_DIR}"/sites-enabled/default
sudo rm -rf "${NGINX_CONF_DIR}"/sites-enabled/otbr-nginx.conf
sudo ln -s "${NGINX_CONF_DIR}"/sites-available/otbr-nginx.conf "${NGINX_CONF_DIR}"/sites-enabled/

if have systemctl; then
sudo systemctl restart nginx
else
echo >&2 ' *** WARNING: systemctl not found. otbr cannot start on boot.'
fi
else
echo >&2 ' *** WARNING: nginx not found, please install nginx manually and run setup again'
fi
}
12 changes: 5 additions & 7 deletions script/_otbr
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ readonly BACKBONE_ROUTER="${BACKBONE_ROUTER:-0}"
otbr_uninstall()
{
if have systemctl; then
sudo systemctl stop otbr-web otbr-agent || true
sudo systemctl disable otbr-web otbr-agent || true
! sudo systemctl is-enabled otbr-web
sudo systemctl stop otbr-agent || true
sudo systemctl disable otbr-agent || true
! sudo systemctl is-enabled
! sudo systemctl is-enabled otbr-agent
fi
sudo killall otbr-web otbr-agent || true
sudo killall otbr-agent || true

(
if cd "${OTBR_TOP_BUILDDIR}"; then
Expand All @@ -66,7 +66,6 @@ otbr_install()
"-DBUILD_TESTING=OFF"
"-DCMAKE_INSTALL_PREFIX=/usr"
"-DOTBR_DBUS=ON"
"-DOTBR_WEB=ON"
"-DOTBR_REST=ON"
"${otbr_options[@]}"
)
Expand All @@ -91,9 +90,8 @@ otbr_install()
if have systemctl; then
sudo systemctl reload dbus
sudo systemctl daemon-reload
sudo systemctl enable otbr-web otbr-agent || true
sudo systemctl enable otbr-agent || true
sudo systemctl is-enabled otbr-agent || die 'Failed to enable otbr-agent!'
sudo systemctl is-enabled otbr-web || die 'Failed to enable otbr-web!'
else
echo >&2 ' *** WARNING: systemctl not found. otbr cannot start on boot.'
fi
Expand Down
7 changes: 4 additions & 3 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ install_packages_apt()
fi
}

# libjsoncpp
sudo apt-get install --no-install-recommends -y libjsoncpp1 libjsoncpp-dev
# nginx
sudo apt-get install --no-install-recommends -y nginx

# reference device
without REFERENCE_DEVICE || sudo apt-get install --no-install-recommends -y radvd
Expand Down Expand Up @@ -115,11 +115,12 @@ install_packages_rpm()
sudo $PM install -y tayga iptables
sudo $PM install -y jsoncpp-devel
sudo $PM install -y wget
sudo $PM install -y nginx
}

install_packages_brew()
{
brew install boost cmake cpputest dbus jsoncpp ninja
brew install cmake cpputest dbus ninja nginx
}

install_packages_source()
Expand Down
5 changes: 2 additions & 3 deletions script/console
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ readonly RADIO_URL="${RADIO_URL:-spinel+hdlc+uart:///dev/ttyUSB0}"
killall_services()
{
echo 'Closing services...'
sudo killall otbr-agent otbr-web || true
sudo killall otbr-agent || true
}

on_exit()
Expand All @@ -54,15 +54,14 @@ main()
{
. "$BEFORE_HOOK"
if have systemctl; then
sudo systemctl stop otbr-web otbr-agent || true
sudo systemctl stop otbr-agent || true
fi
killall_services

trap on_exit INT TERM EXIT
ipforward_enable
sudo sh -s <<EOF
otbr-agent -I $TUN "${RADIO_URL}" &
otbr-web -I $TUN &
wait
EOF
}
Expand Down
2 changes: 0 additions & 2 deletions script/server
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ main()
systemctl is-active rsyslog || sudo systemctl start rsyslog || die 'Failed to start rsyslog!'
systemctl is-active dbus || sudo systemctl start dbus || die 'Failed to start dbus!'
systemctl is-active avahi-daemon || sudo systemctl start avahi-daemon || die 'Failed to start avahi!'
systemctl is-active otbr-web || sudo systemctl start otbr-web || die 'Failed to start otbr-web!'
systemctl is-active otbr-agent || sudo systemctl start otbr-agent || die 'Failed to start otbr-agent!'
elif have service; then
sudo service rsyslog status || sudo service rsyslog start || die 'Failed to start rsyslog!'
sudo service dbus status || sudo service dbus start || die 'Failed to start dbus!'
sudo service avahi-daemon status || sudo service avahi-daemon start || die 'Failed to start avahi!'
sudo service otbr-agent status || sudo service otbr-agent start || die 'Failed to start otbr-agent!'
sudo service otbr-web status || sudo service otbr-web start || die 'Failed to start otbr-web!'
else
die 'Unable to find service manager. Try script/console to start in console mode!'
fi
Expand Down
2 changes: 2 additions & 0 deletions script/setup
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
. script/_swapfile
. script/_sudo_extend
. script/_disable_services
. script/_nginx_config_install

main()
{
Expand All @@ -64,6 +65,7 @@ main()
network_manager_install
dhcpv6_pd_install
otbr_install
nginx_config_install
. "$AFTER_HOOK"
}

Expand Down
2 changes: 0 additions & 2 deletions script/test
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ do_build()
"-DCMAKE_BUILD_TYPE=Debug"
"-DCMAKE_INSTALL_PREFIX=/usr"
"-DOTBR_DBUS=ON"
"-DOTBR_WEB=ON"
"-DOTBR_UNSECURE_JOIN=ON"
${otbr_options[@]+"${otbr_options[@]}"}
)
Expand Down Expand Up @@ -161,7 +160,6 @@ do_package()
"-DBUILD_TESTING=OFF"
"-DCMAKE_INSTALL_PREFIX=/usr"
"-DCMAKE_BUILD_TYPE=Release"
"-DOTBR_WEB=ON"
${otbr_options[@]+"${otbr_options[@]}"}
)

Expand Down
4 changes: 0 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ if(OTBR_OPENWRT)
add_subdirectory(openwrt)
endif()

if(OTBR_WEB)
add_subdirectory(web)
endif()

if(OTBR_REST)
add_subdirectory(rest)
endif()
tttttangTH marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion src/agent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include "common/types.hpp"
#if OTBR_ENABLE_REST_SERVER
#include "rest/rest_web_server.hpp"
using otbr::rest::RestWebServer;
using otbr::Rest::RestWebServer;
#endif
#if OTBR_ENABLE_DBUS_SERVER
#include "dbus/server/dbus_agent.hpp"
Expand Down
6 changes: 6 additions & 0 deletions src/rest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ target_link_libraries(otbr-rest
http_parser
PRIVATE
cjson
mbedtls
otbr-config
otbr-utils
openthread-ftd
openthread-posix
)

install(DIRECTORY frontend
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
DESTINATION /var/otbr
)
Loading