Skip to content

Commit

Permalink
replace otbr-web
Browse files Browse the repository at this point in the history
  • Loading branch information
tttttangTH committed Oct 13, 2020
1 parent 425696f commit 60a7974
Show file tree
Hide file tree
Showing 61 changed files with 2,213 additions and 2,390 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
runs-on: ubuntu-18.04
strategy:
matrix:
rest: ["rest", ""]
rest: ["rest off", ""]
env:
BUILD_TARGET: check
OTBR_REST: ${{ matrix.rest }}
Expand Down
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 "$@"
11 changes: 0 additions & 11 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 Down
3 changes: 1 addition & 2 deletions etc/docker/docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ NAT64_PREFIX=${NAT64_PREFIX/\//\\\/}
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
echo "OTBR_AGENT_OPTS=\"-I $TUN_INTERFACE_NAME -d7 $RADIO_URL\"" >/etc/default/otbr-agent

/app/script/server

Expand Down
135 changes: 135 additions & 0 deletions etc/rest/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#
# 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.
#

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Basic Settings
##
server {
listen 80;
server_name 0.0.0.0;

#access_log /var/log/nginx/localhost.access.log;

location / {
root to be set;
index index.html ;
}
location /favicon.ico
{
root to be set/res/img;
}
location /v1/ {
proxy_pass http://0.0.0.0:8081;
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;
}


}

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}


#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS"; #
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
50 changes: 50 additions & 0 deletions script/_nginx_server_install
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/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.
#

nginx_server_install()
{
if command -v nginx; then

top_dir="$(pwd)"

nginx_conf_file=$(nginx -V 2>&1 | grep -o "\-\-conf-path=\(.*conf\)" | cut -d "=" -f2)

sudo rm "${nginx_conf_file}"

sudo cp "${top_dir}"/etc/rest/nginx.conf "${nginx_conf_file}"

sudo sed -i.bak "s:to be set:${top_dir}/src/rest/frontend:" "${nginx_conf_file}"

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 @@ -35,12 +35,12 @@ readonly REFERENCE_DEVICE=${REFERENCE_DEVICE:-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 Down Expand Up @@ -72,7 +72,6 @@ otbr_install()
"-DBUILD_TESTING=OFF"
"-DCMAKE_INSTALL_PREFIX=/usr"
"-DOTBR_DBUS=ON"
"-DOTBR_WEB=ON"
"-DOTBR_REST=ON"
"${otbr_options[@]}"
)
Expand All @@ -92,9 +91,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
6 changes: 5 additions & 1 deletion script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ install_packages_apt()

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

# nginx
sudo apt-get install --no-install-recommends -y nginx
}

install_packages_opkg()
Expand All @@ -109,11 +112,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 @@ -41,6 +41,7 @@
. script/_swapfile
. script/_sudo_extend
. script/_disable_services
. script/_nginx_server_install

main()
{
Expand All @@ -60,6 +61,7 @@ main()
dns64_install
network_manager_install
dhcpv6_pd_install
nginx_server_install
otbr_install
. "$AFTER_HOOK"
}
Expand Down
Loading

0 comments on commit 60a7974

Please sign in to comment.