Compare commits

..

21 Commits

Author SHA1 Message Date
Vivek Teega
cd47df5c8c Merge branch 'main' of https://github.com/ranchimall/Flo-Token-System-Docker into main 2022-07-24 12:15:26 +00:00
Vivek Teega
2632b3d785 v1.0.1 Leaner image than version 1.0.0 2022-07-24 12:09:06 +00:00
Vivek Teega
f6a001d531
Update README.md 2022-07-18 20:10:46 +05:30
Vivek Teega
0d4f0f663c Merge branch 'main' of https://github.com/ranchimall/Flo-Token-System-Docker into main 2022-07-18 11:28:26 +00:00
Vivek Teega
00e5b47af4 Fixed bugs 2022-07-18 11:28:05 +00:00
Vivek Teega
b77614c488
Update README.md 2022-07-18 14:56:35 +05:30
Vivek Teega
cf8bbd847e
Update README.md 2022-07-18 14:56:03 +05:30
Vivek Teega
3698caee7b Mongoose server changes 2022-07-17 18:40:21 +05:30
Vivek Teega
9439cc238e Added files required to create mongoose binary 2022-07-17 18:24:31 +05:30
Vivek Teega
c10075d254 Socket.io module bug fix | added absolute paths to services in supervisord 2022-07-17 12:30:42 +00:00
Vivek Teega
3f7c6f8e6d install unzip 2022-07-17 15:53:14 +05:30
Vivek Teega
5d0c8faa89 Added data path to Token Tracking & Ranchimallflo api config to accomodate new version of token tracking 2022-07-17 14:13:04 +05:30
cda08e7617
Created /data folder for bootstrap mounting 2022-07-17 13:39:00 +05:30
4b6d826339
Update run.sh 2022-07-17 13:35:00 +05:30
4bb36a096b
Update README.md 2022-07-17 13:33:30 +05:30
a7a0d8c987
Update README.md 2022-07-17 12:15:51 +05:30
Divyansh Bhardwaj
b3cbb729c1 Added commands for docker volume creation 2022-07-05 22:30:32 +05:30
Divyansh Bhardwaj
f5a6851c73 Changed the binary
Added commands for docker volume creation
2022-07-05 22:29:55 +05:30
Vivek Teega
1cc6e32d5e Fixed bug: Dockerfile not executing run.sh 2022-07-04 19:54:21 +00:00
Divyansh Bhardwaj
c048a31bbf Changes in run.sh for floscout APu url 2022-07-03 01:09:06 +05:30
Divyansh Bhardwaj
7c8567fb07 Changes in run.sh for floscout APu url 2022-06-27 23:46:23 +05:30
15 changed files with 8589 additions and 85 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.iml
*.xml

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

1
.idea/.name Normal file
View File

@ -0,0 +1 @@
Dockerfile

View File

@ -1,103 +1,50 @@
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "-c"]
EXPOSE 6200
EXPOSE 6012
LABEL ranchimall="ranchimallfze@gmail.com"
CMD { "echo", "Ranchi Mall" }
## for apt to be noninteractive
# for apt to be noninteractive
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
RUN apt-get update
RUN apt-get -y install python3-pip
RUN apt-get -y install git
RUN apt-get -y install python-chardet python3.9 python3.9-venv
RUN apt-get -y install libsecp256k1-dev libssl-dev build-essential automake pkg-config libtool libffi-dev libgmp-dev libyaml-cpp-dev
RUN apt-get install supervisor
RUN apt-get update && apt-get -y --no-install-recommends install python3-pip python3-venv git curl unzip supervisor libsecp256k1-dev build-essential make systemd && rm -rf /var/lib/apt/lists/*
# libssl-dev automake pkg-config libtool libffi-dev libgmp-dev libyaml-cpp-dev libleveldb-dev
# Installation of Pybtc, currently named as Pyflo
WORKDIR ../
RUN git clone https://github.com/ranchimall/pyflo
WORKDIR pyflo
RUN apt-get install -y pkg-config
RUN python3 setup.py install
WORKDIR ../
# Clone all required git folders
WORKDIR /
RUN git clone https://github.com/ranchimall/pyflo && git clone --branch token-swap https://github.com/ranchimall/flo-token-tracking.git && git clone https://github.com/ranchimall/ranchimallflo-api && git clone https://github.com/ranchimall/floscout.git
# Setup of Flo Token Tracker
RUN git clone https://github.com/vivekteega/ftt-docker
WORKDIR ftt-docker
#RUN python3.9 -m venv ftt
#RUN . ftt/bin/activate
RUN python3 -m pip install chardet
RUN python3 -m pip install arrow
RUN python3 -m pip install socketio
RUN python3 -m pip install requests
RUN sed -i "s|chardet==4.0.0|chardet|g" /ftt-docker/requirements.txt
RUN touch config.ini
RUN echo "[DEFAULT] \n\
NET = testnet \n\
FLO_CLI_PATH = /usr/local/bin/flo-cli \n\
START_BLOCK = 740400" >> /ftt-docker/config.ini
RUN touch config.py
RUN echo "committeeAddressList = ['oVwmQnQGtXjRpP7dxJeiRGd5azCrJiB6Ka'] \n\
sseAPI_url = 'https://ranchimallflo-testnet.duckdns.org/' \n\
privKey = 'RG6Dni1fLqeT2TEFbe7RB9tuw53bDPDXp8L4KuvmYkd5JGBam6KJ' " >> /ftt-docker/config.py
WORKDIR /flo-token-tracking
RUN python3 -m venv env && ./env/bin/python3 -m pip install -r requirements.txt && ./env/bin/python3 /pyflo/setup.py install && touch config.ini && touch config.py
RUN if [[ $NETWORK=='test' ]] ; then echo "[DEFAULT]\nNET = testnet\nFLO_CLI_PATH = /usr/local/bin/flo-cli\nSTART_BLOCK = 740400\nFLOSIGHT_NETURL = https://testnet-flosight.duckdns.org/\nTESTNET_FLOSIGHT_SERVER_LIST = https://testnet-flosight.duckdns.org/\nMAINNET_FLOSIGHT_SERVER_LIST = https://flosight.duckdns.org/\nTOKENAPI_SSE_URL = https://ranchimallflo-testnet.duckdns.org\nDATA_PATH=/data\nIGNORE_BLOCK_LIST = 902446\nIGNORE_TRANSACTION_LIST = b4ac4ddb51188b28b39bcb3aa31357d5bfe562c21e8aaf8dde0ec560fc893174" >> /flo-token-tracking/config.ini ; else echo "[DEFAULT]\nNET = mainnet\nFLO_CLI_PATH = /usr/local/bin/flo-cli\nSTART_BLOCK = 3387900\nFLOSIGHT_NETURL = https://flosight.duckdns.org/\nTESTNET_FLOSIGHT_SERVER_LIST = https://testnet-flosight.duckdns.org/\nMAINNET_FLOSIGHT_SERVER_LIST = https://flosight.duckdns.org/\nTOKENAPI_SSE_URL = https://ranchimallflo.duckdns.org\nDATA_PATH=/data\nIGNORE_BLOCK_LIST = 902446\nIGNORE_TRANSACTION_LIST = b4ac4ddb51188b28b39bcb3aa31357d5bfe562c21e8aaf8dde0ec560fc893174" >> /flo-token-tracking/config.ini ; fi
RUN if [[ $NETWORK=='test' ]] ; then echo "committeeAddressList = ['oVwmQnQGtXjRpP7dxJeiRGd5azCrJiB6Ka'] \nsseAPI_url = 'https://ranchimallflo-testnet.duckdns.org/' \nprivKey = 'RG6Dni1fLqeT2TEFbe7RB9tuw53bDPDXp8L4KuvmYkd5JGBam6KJ' " >> /flo-token-tracking/config.py ; else echo "committeeAddressList = ['FRwwCqbP7DN4z5guffzzhCSgpD8Q33hUG8'] \nsseAPI_url = 'https://ranchimallflo.duckdns.org/' \nprivKey = 'RG6Dni1fLqeT2TEFbe7RB9tuw53bDPDXp8L4KuvmYkd5JGBam6KJ' " >> /flo-token-tracking/config.py ; fi
# Setup of RanchimallFlo API
RUN git clone https://github.com/ranchimall/ranchimallflo-api
WORKDIR ranchimallflo-api
RUN python3 -m pip install --upgrade pip setuptools wheel
RUN python3 -m pip install -r requirements.txt
RUN pip3 install apscheduler
RUN touch config.py
RUN echo "dbfolder = '/home/production/dev/shivam/ranchimallflo-api' \n\
sse_pubKey = '02b68a7ba52a499b4cb664033f511a14b0b8b83cd3b2ffcc7c763ceb9e85caabcf' \n\
apiUrl = 'https://flosight.duckdns.org/api/' \n\
apilayerAccesskey = '3abc51aa522420e4e185ac22733b0f30' \n\
FLO_DATA_DIR = '/home/production/.flo' " >> /config.py
WORKDIR /ranchimallflo-api
RUN python3 -m venv env && ./env/bin/python3 -m pip install --upgrade pip setuptools wheel && ./env/bin/python3 -m pip install -r requirements.txt
RUN touch config.py && echo "dbfolder = '/data' \nsse_pubKey = '02b68a7ba52a499b4cb664033f511a14b0b8b83cd3b2ffcc7c763ceb9e85caabcf' \napiUrl = 'https://flosight.duckdns.org/api/' \napilayerAccesskey = '3abc51aa522420e4e185ac22733b0f30' \nFLO_DATA_DIR = '/home/production/.flo' " >> /ranchimallflo-api/config.py
WORKDIR /pyflo
RUN /ranchimallflo-api/env/bin/python3 setup.py install
RUN /flo-token-tracking/env/bin/python3 setup.py install
# Setup of Floscout
#WORKDIR /floscout
#RUN sed -i "s|window.tokenapiUrl = 'http://0.0.0.0:6012'|window.tokenapiUrl = $FLOAPIURL|" /floscout/index.html
# Supervisor configurations
## Ranchimallflo configuration
WORKDIR /etc/supervisor/conf.d/
RUN touch ranchimallflo-api.conf
RUN echo "[program:ranchimallflo-api]\n\
directory=/ranchimallflo-api\n\
command=/ranchimallflo-api/py3.7/bin/hypercorn -w 1 -b 0.0.0.0:5009 wsgi:app\n\
user=root\n\
autostart=true\n\
autorestart=true\n\
stopasgroup=true\n\
killasgroup=true\n\
stderr_logfile=/var/log/ranchimallflo-api/ranchimallflo-api.err.log \n\
stdout_logfile=/var/log/ranchimallflo-api/ranchimallflo-api.out.log" >> ranchimallflo-api.conf
RUN mkdir /var/log/ranchimallflo-api/
RUN touch /var/log/ranchimallflo-api/ranchimallflo-api.err.log
RUN touch /var/log/ranchimallflo-api/ranchimallflo-api.out.log
RUN touch ftt-ranchimallflo.conf
RUN echo "[supervisord] \nnodaemon=true\n[program:flo-token-tracking]\ndirectory=/flo-token-tracking\ncommand=/flo-token-tracking/env/bin/python3 tracktokens_smartcontracts.py\nuser=root\nautostart=true\nautorestart=false\nstopasgroup=true\nkillasgroup=true\nstderr_logfile=/var/log/flo-token-tracking/flo-token-tracking.err.log\nstdout_logfile=/var/log/flo-token-tracking/flo-token-tracking.out.log\n[program:ranchimallflo-api]\ndirectory=/ranchimallflo-api\ncommand=/ranchimallflo-api/env/bin/hypercorn -w 1 -b 0.0.0.0:6012 wsgi:app\nuser=root\nautostart=true\nautorestart=true\nstopasgroup=true\nkillasgroup=true\nstderr_logfile=/var/log/ranchimallflo-api/ranchimallflo-api.err.log \nstdout_logfile=/var/log/ranchimallflo-api/ranchimallflo-api.out.log\n[program:floscout]\ndirectory=/floscout\ncommand=/floscout/example\nuser=root\nautostart=true\nautorestart=false\nstopasgroup=true\nkillasgroup=true\nstderr_logfile=/var/log/floscout/floscout.err.log\nstdout_logfile=/var/log/floscout/floscout.out.log\n" >> ftt-ranchimallflo.conf
RUN mkdir /var/log/flo-token-tracking && touch /var/log/flo-token-tracking/flo-token-tracking.err.log && touch /var/log/flo-token-tracking/flo-token-tracking.out.log && mkdir /var/log/ranchimallflo-api/ && touch /var/log/ranchimallflo-api/ranchimallflo-api.err.log && touch /var/log/ranchimallflo-api/ranchimallflo-api.out.log && mkdir /var/log/floscout/ && touch /var/log/floscout/floscout.err.log && touch /var/log/floscout/floscout.out.log
## Flo token tracking configuration
RUN touch ftt.conf
RUN echo "[program:ftt-docker]\n\
directory=ftt-docker\n\
command=tracktokens-smartcontracts.py\n\
user=root\n\
autostart=true\n\
autorestart=true\n\
stopasgroup=true\n\
killasgroup=true\n\
stderr_logfile=/var/log/flo-token-tracking/flo-token-tracking.err.log\n\
stdout_logfile=/var/log/flo-token-tracking/flo-token-tracking.out.log" >> ftt.conf
RUN mkdir /var/log/flo-token-tracking
RUN touch /var/log/flo-token-tracking/flo-token-tracking.err.log
RUN touch /var/log/flo-token-tracking/flo-token-tracking.out.log
# Run supervisor
RUN service supervisor restart
RUN mkdir /data
WORKDIR /
RUN mkdir mongoose-server
COPY mongoose-server/ /mongoose-server
COPY run.sh .
RUN chmod +x run.sh
ENTRYPOINT ["sh","/run.sh"]

View File

@ -2,7 +2,7 @@
Docker resources to build components required for FLO Token-Smart Contract system, all at one place!
## Why do I need this?
## Why do I need this?
FLO Token-Smart Contract system consists of three apps working together
* FLO Token & Smart Contract tracking scripts (Python)
@ -13,8 +13,72 @@ RanchiMall wants to made things easy for you by packing all the three systems to
## How do I use this?
Clone the repository and then run
Clone the repository and build the docker image by the following command
```
sudo docker build .
```
Crete a docker volume
```
docker volume inspect ranchimall-flo-volume
```
Run the docker container with exposing all the port and mounting the volume
```
docker run -it -p 3023:3023 -p 6200:6200 -p 6012:6012 -v ranchimall-flo-volume --env NETWORKK='test' --env FLOAPIURL="0.0.0.0:3023" <IMAGE-ID>
```
To Check if FLO-API is running
```
http://0.0.0.0:5009/api/v1.0/getSystemData
```
To Check if FLOSCOUT is running
```
http://0.0.0.0:4256
```
## Development of the docker commands for regular Floscout on Docker
```
docker volume create floscout
docker run -d --name=floscout \
-p 6200:6200 -p 6012:6012 \
-v floscout:/data \
-e NETWORK=mainnet \
-e FLOSCOUT_BOOTSTRAP=http://ranchimall-stevejobs.duckdns.org:3847/data.zip \
ranchimallfze/floscout:1.0.0
docker logs -f floscout
```
## FLOSCOUT BOOTSTRAP CODE (To be removed after code is incorporated)
```
if [ ! -z "$FLOSCOUT_BOOTSTRAP" ] && [ "$(cat /data/floscout-url.txt)" != "$FLOSCOUT_BOOTSTRAP" ]
then
# download and extract Floscout boostrap
echo 'Downloading FLOSCOUT Bootstrap...'
RUNTIME="$(date +%s)"
curl -L $FLOSCOUT_BOOTSTRAP -o /data/data.zip --progress-bar | tee /dev/null
RUNTIME="$(($(date +%s)-RUNTIME))"
echo "FLOSCOUT BOOTSTRAP Download Complete (took ${RUNTIME} seconds)"
echo 'Extracting Bootstrap...'
RUNTIME="$(date +%s)"
upzip /data/data.zip -d /data
RUNTIME="$(($(date +%s)-RUNTIME))"
echo "FLOSCOUT Bootstrap Extraction Complete! (took ${RUNTIME} seconds)"
rm -f /data/data.zip
echo 'Erased Bootstrap `.zip` file'
echo "$FLOSCOUT_BOOTSTRAP" > /data/floscout-url.txt
ls /data
fi
```

1
flo.sh Normal file
View File

@ -0,0 +1 @@
sed -i "s|window.tokenapiUrl = 'http://0.0.0.0:6012'|window.tokenapiUrl = '$FLOAPIURL'|" /floscout/index.html

163
mongoose-server/Makefile Normal file
View File

@ -0,0 +1,163 @@
SRCS = mongoose.c test/unit_test.c test/packed_fs.c
HDRS = $(wildcard src/*.h) $(wildcard mip/*.h)
DEFS ?= -DMG_MAX_HTTP_HEADERS=7 -DMG_ENABLE_LINES -DMG_ENABLE_PACKED_FS=1 -DMG_ENABLE_SSI=1
C_WARN ?= -Wmissing-prototypes -Wstrict-prototypes
WARN ?= -pedantic -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef $(C_WARN)
OPTS ?= -O3 -g3
VALGRIND_OPTS ?= -O0 -g3
INCS ?= -Isrc -I.
SSL ?= MBEDTLS
CWD ?= $(realpath $(CURDIR))
ENV ?= -e Tmp=. -e WINEDEBUG=-all
DOCKER ?= docker run --rm $(ENV) -v $(CWD):$(CWD) -w $(CWD)
VCFLAGS = /nologo /W3 /O2 /MD /I. $(DEFS) $(TFLAGS)
IPV6 ?= 1
ASAN ?= -fsanitize=address,undefined -fno-sanitize-recover=all
ASAN_OPTIONS ?= detect_leaks=1
EXAMPLES := $(dir $(wildcard examples/*/Makefile)) examples/stm32/nucleo-f746zg-baremetal
PREFIX ?= /usr/local
VERSION ?= $(shell cut -d'"' -f2 src/version.h)
COMMON_CFLAGS ?= $(WARN) $(INCS) $(DEFS) -DMG_ENABLE_IPV6=$(IPV6) $(TFLAGS)
CFLAGS ?= $(OPTS) $(ASAN) $(COMMON_CFLAGS)
VALGRIND_CFLAGS ?= $(VALGRIND_OPTS) $(COMMON_CFLAGS)
VALGRIND_RUN ?= valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --show-leak-kinds=all --leak-resolution=high --track-origins=yes --error-exitcode=1 --exit-on-first-error=yes
.PHONY: examples test valgrind
ifeq "$(SSL)" "MBEDTLS"
MBEDTLS ?= /usr/local
CFLAGS += -DMG_ENABLE_MBEDTLS=1 -I$(MBEDTLS)/include -I/usr/include
LDFLAGS ?= -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509
endif
ifeq "$(SSL)" "OPENSSL"
OPENSSL ?= /usr/local
CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL)/include
LDFLAGS ?= -L$(OPENSSL)/lib -lssl -lcrypto
endif
all: mg_prefix unamalgamated unpacked test test++ valgrind arm examples vc98 vc2017 vc22 mingw mingw++ linux linux++ fuzz
examples:
@for X in $(EXAMPLES); do test -f $$X/Makefile || continue; $(MAKE) -C $$X example || exit 1; done
test/packed_fs.c: Makefile src/ssi.h test/fuzz.c test/data/a.txt
$(CC) $(CFLAGS) test/pack.c -o pack
./pack Makefile src/ssi.h test/fuzz.c test/data/a.txt test/data/range.txt > $@
DIR ?= test/data/
OUT ?= fs_packed.c
mkfs:
$(CC) $(CFLAGS) test/pack.c -o pack
./pack -s $(DIR) `find $(DIR) -type f` > $(OUT)
# find $(DIR) -type f | sed -e s,^$(DIR),,g -e s,^/,,g
# Check that all external (exported) symbols have "mg_" prefix
mg_prefix: mongoose.c mongoose.h
$(CC) mongoose.c $(CFLAGS) -c -o /tmp/x.o && nm /tmp/x.o | grep ' T' | grep -v 'mg_' ; test $$? = 1
# C++ build
test++: CC = g++
test++: C_WARN = -std=c++2a -Wno-vla -Wno-shadow -Wno-missing-field-initializers -Wno-deprecated
test++: test
musl: test
musl: ASAN =
musl: WARN += -Wno-sign-conversion
musl: CC = $(DOCKER) mdashnet/cc1 gcc
# Make sure we can build from an unamalgamated sources
unamalgamated: $(HDRS) Makefile test/packed_fs.c
$(CC) src/*.c test/packed_fs.c test/unit_test.c $(CFLAGS) $(LDFLAGS) -g -o unit_test
unpacked:
$(CC) -I. mongoose.c test/unit_test.c -o $@
fuzzer: mongoose.c mongoose.h Makefile test/fuzz.c
clang++ mongoose.c test/fuzz.c $(WARN) $(INCS) $(TFLAGS) -DMG_ENABLE_LINES -fsanitize=fuzzer,signed-integer-overflow,address -Wno-deprecated -Wno-vla-extension -o $@
fuzz: fuzzer
$(RUN) ./fuzzer
unit_test: Makefile mongoose.h $(SRCS)
$(CC) $(SRCS) $(CFLAGS) $(LDFLAGS) -g -o unit_test
# make CC=/usr/local/opt/llvm\@8/bin/clang ASAN_OPTIONS=detect_leaks=1
test: unit_test
ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./unit_test
coverage: CFLAGS += -coverage
coverage: test
gcov -l -n *.gcno | sed '/^$$/d' | sed 'N;s/\n/ /'
gcov -t mongoose.c > mongoose.gcov
upload-coverage: coverage
curl -s https://codecov.io/bash | /bin/bash
valgrind_unit_test: Makefile mongoose.h $(SRCS)
$(CC) $(SRCS) $(VALGRIND_CFLAGS) $(LDFLAGS) -g -o valgrind_unit_test
valgrind: valgrind_unit_test
$(VALGRIND_RUN) ./valgrind_unit_test
infer:
infer run -- cc test/unit_test.c -c -W -Wall -Werror -Isrc -I. -O2 -DMG_ENABLE_MBEDTLS=1 -DMG_ENABLE_LINES -I/usr/local/Cellar/mbedtls/2.23.0/include -DMG_ENABLE_IPV6=1 -g -o /dev/null
arm: DEFS += -DMG_ENABLE_FILE=0 -DMG_ENABLE_MIP=1 -DMG_ARCH=MG_ARCH_NEWLIB
arm: mongoose.h $(SRCS)
$(DOCKER) mdashnet/armgcc arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb $(SRCS) $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) -o unit_test -nostartfiles --specs nosys.specs -e 0
riscv: DEFS += -DMG_ENABLE_FILE=0 -DMG_ENABLE_MIP=1 -DMG_ARCH=MG_ARCH_NEWLIB
riscv: mongoose.h $(SRCS)
$(DOCKER) mdashnet/riscv riscv-none-elf-gcc -march=rv32imc -mabi=ilp32 $(SRCS) $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) -o unit_test
vc98: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/vc98 wine cl $(SRCS) $(VCFLAGS) ws2_32.lib /Fe$@.exe
$(DOCKER) mdashnet/vc98 wine $@.exe
# vc2017: DEFS += -DMG_ENABLE_IPV6=1
vc2017: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/vc2017 wine64 cl $(SRCS) $(VCFLAGS) ws2_32.lib /Fe$@.exe
$(DOCKER) mdashnet/vc2017 wine64 $@.exe
# vc22: DEFS += -DMG_ENABLE_IPV6=$(IPV6)
vc22: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/vc22 wine64 cl $(SRCS) $(VCFLAGS) ws2_32.lib /Fe$@.exe
$(DOCKER) mdashnet/vc22 wine64 $@.exe
mingw: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/mingw x86_64-w64-mingw32-gcc $(SRCS) -W -Wall -Werror -I. $(DEFS) -lwsock32 -o $@.exe
$(DOCKER) mdashnet/mingw wine64 $@.exe
mingw++: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/mingw x86_64-w64-mingw32-g++ $(SRCS) -W -Wall -Werror -I. $(DEFS) -lwsock32 -o $@.exe
linux: IPV6=0
linux: Makefile mongoose.h $(SRCS)
$(DOCKER) mdashnet/cc2 gcc $(SRCS) $(CFLAGS) $(LDFLAGS) -o unit_test_gcc
$(DOCKER) mdashnet/cc2 ./unit_test_gcc
linux++: CC = g++
linux++: WARN += -Wno-missing-field-initializers
linux++: linux
linux-libs: CFLAGS += -fPIC
linux-libs: mongoose.o
$(CC) mongoose.o $(LDFLAGS) -shared -o libmongoose.so.$(VERSION)
$(AR) rcs libmongoose.a mongoose.o
install: linux-libs
install -Dm644 libmongoose.a libmongoose.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib
ln -s libmongoose.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libmongoose.so
install -Dm644 mongoose.h $(DESTDIR)$(PREFIX)/include/mongoose.h
uninstall:
rm -rf $(DESTDIR)$(PREFIX)/lib/libmongoose.a $(DESTDIR)$(PREFIX)/lib/libmongoose.so.$(VERSION) $(DESTDIR)$(PREFIX)/include/mongoose.h $(DESTDIR)$(PREFIX)/lib/libmongoose.so
mongoose.c: Makefile $(wildcard src/*) $(wildcard mip/*.c)
(cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/*.c mip/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@
mongoose.h: $(HDRS) Makefile
(cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/config.h src/str.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h src/json.h mip/mip.h | sed -e 's,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
clean:
rm -rf $(PROG) *.exe *.o *.dSYM unit_test* valgrind_unit_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out data.txt crash-* test/packed_fs.c pack unpacked
@for X in $(EXAMPLES); do $(MAKE) -C $$X clean; done

BIN
mongoose-server/examples/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,26 @@
PROG ?= example
ROOT ?= $(realpath $(CURDIR)/../..)
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_IPV6=1 -DMG_ENABLE_SSI=1
CFLAGS ?= -I../.. -W -Wall $(DEFS) $(EXTRA)
VCFLAGS = /nologo /W3 /O2 /I../.. $(DEFS) $(EXTRA) /link /incremental:no /machine:IX86
VC98 = docker run -it --rm -e Tmp=. -v $(ROOT):$(ROOT) -w $(CURDIR) mdashnet/vc98
LIN = docker run -it --rm -v $(ROOT):$(ROOT) -w $(CURDIR) mdashnet/cc2
#all: $(PROG)
# $(RUN) ./$(PROG) $(ARGS)
$(PROG): main.c Makefile
$(CC) ../../mongoose.c main.c -I../.. $(CFLAGS) -o $@
mongoose.exe: main.c
$(VC98) wine cl ../../mongoose.c main.c $(VCFLAGS) ws2_32.lib /out:$@
mingw:
gcc ../../mongoose.c main.c -I../.. -W -Wall -DMG_ENABLE_IPV6=1 -DMG_ENABLE_LINES=1 -D_POSIX_C_SOURCE=200000L -lws2_32 -o mongoose.exe
linux: example
#linux: CFLAGS += -O2 -fsanitize=address,undefined,shift,null,return,bounds,alignment,object-size,bool,enum -static-libasan
linux: CC = $(LIN) cc
clean:
rm -rf $(PROG) *.o *.dSYM *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb mongoose mongoose_* mongoose.*

View File

@ -0,0 +1 @@
See detailed tutorial at https://mongoose.ws/tutorials/http-server/

View File

@ -0,0 +1,103 @@
// Copyright (c) 2020 Cesanta Software Limited
// All rights reserved
#include <signal.h>
#include "mongoose.h"
static const char *s_debug_level = "2";
static const char *s_root_dir = ".";
static const char *s_listening_address = "http://0.0.0.0:6200";
static const char *s_enable_hexdump = "no";
static const char *s_ssi_pattern = "#.html";
// Handle interrupts, like Ctrl-C
static int s_signo;
static void signal_handler(int signo) {
s_signo = signo;
}
// Event handler for the listening connection.
// Simply serve static files from `s_root_dir`
static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = ev_data, tmp = {0};
struct mg_str unknown = mg_str_n("?", 1), *cl;
struct mg_http_serve_opts opts = {0};
opts.root_dir = s_root_dir;
opts.ssi_pattern = s_ssi_pattern;
mg_http_serve_dir(c, hm, &opts);
mg_http_parse((char *) c->send.buf, c->send.len, &tmp);
cl = mg_http_get_header(&tmp, "Content-Length");
if (cl == NULL) cl = &unknown;
MG_INFO(("%.*s %.*s %.*s %.*s", (int) hm->method.len, hm->method.ptr,
(int) hm->uri.len, hm->uri.ptr, (int) tmp.uri.len, tmp.uri.ptr,
(int) cl->len, cl->ptr));
}
(void) fn_data;
}
static void usage(const char *prog) {
fprintf(stderr,
"Mongoose v.%s\n"
"Usage: %s OPTIONS\n"
" -H yes|no - enable traffic hexdump, default: '%s'\n"
" -S PAT - SSI filename pattern, default: '%s'\n"
" -d DIR - directory to serve, default: '%s'\n"
" -l ADDR - listening address, default: '%s'\n"
" -v LEVEL - debug level, from 0 to 4, default: '%s'\n",
MG_VERSION, prog, s_enable_hexdump, s_ssi_pattern, s_root_dir,
s_listening_address, s_debug_level);
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]) {
char path[MG_PATH_MAX] = ".";
struct mg_mgr mgr;
struct mg_connection *c;
int i;
// Parse command-line flags
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-d") == 0) {
s_root_dir = argv[++i];
} else if (strcmp(argv[i], "-H") == 0) {
s_enable_hexdump = argv[++i];
} else if (strcmp(argv[i], "-S") == 0) {
s_ssi_pattern = argv[++i];
} else if (strcmp(argv[i], "-l") == 0) {
s_listening_address = argv[++i];
} else if (strcmp(argv[i], "-v") == 0) {
s_debug_level = argv[++i];
} else {
usage(argv[0]);
}
}
// Root directory must not contain double dots. Make it absolute
// Do the conversion only if the root dir spec does not contain overrides
if (strchr(s_root_dir, ',') == NULL) {
realpath(s_root_dir, path);
s_root_dir = path;
}
// Initialise stuff
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
mg_log_set(s_debug_level);
mg_mgr_init(&mgr);
if ((c = mg_http_listen(&mgr, s_listening_address, cb, &mgr)) == NULL) {
MG_ERROR(("Cannot listen on %s. Use http://ADDR:PORT or :PORT",
s_listening_address));
exit(EXIT_FAILURE);
}
if (mg_casecmp(s_enable_hexdump, "yes") == 0) c->is_hexdumping = 1;
// Start infinite event loop
MG_INFO(("Mongoose version : v%s", MG_VERSION));
MG_INFO(("Listening on : %s", s_listening_address));
MG_INFO(("Web root : [%s]", s_root_dir));
while (s_signo == 0) mg_mgr_poll(&mgr, 1000);
mg_mgr_free(&mgr);
MG_INFO(("Exiting on signal %d", s_signo));
return 0;
}

6776
mongoose-server/mongoose.c Normal file

File diff suppressed because it is too large Load Diff

1383
mongoose-server/mongoose.h Normal file

File diff suppressed because it is too large Load Diff

33
run.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# prepare binary
cd /mongoose-server/examples/http-server
make
chmod +x example
cp example /floscout
if [ ! -z "$FLOSCOUT_BOOTSTRAP" ] && [ "$(cat /data/floscout-url.txt)" != "$FLOSCOUT_BOOTSTRAP" ]
then
# download and extract Floscout boostrap
echo 'Downloading FLOSCOUT Bootstrap...'
RUNTIME="$(date +%s)"
curl -L $FLOSCOUT_BOOTSTRAP -o /data/data.zip --progress-bar | tee /dev/null
RUNTIME="$(($(date +%s)-RUNTIME))"
echo "FLOSCOUT BOOTSTRAP Download Complete (took ${RUNTIME} seconds)"
echo 'Extracting Bootstrap...'
RUNTIME="$(date +%s)"
unzip /data/data.zip -d /data
RUNTIME="$(($(date +%s)-RUNTIME))"
echo "FLOSCOUT Bootstrap Extraction Complete! (took ${RUNTIME} seconds)"
rm -f /data/data.zip
echo 'Erased Bootstrap `.zip` file'
echo "$FLOSCOUT_BOOTSTRAP" > /data/floscout-url.txt
ls /data
fi
cd /etc/supervisor/conf.d/
sed -i "s|command=hypercorn -w 1 -b 0.0.0.0:6012 wsgi:app|command=hypercorn -w 1 -b $FLOAPIURL wsgi:app|" /etc/supervisor/conf.d/ftt-ranchimallflo.conf
sed -i "s|window.tokenapiUrl = 'https://ranchimallflo.duckdns.org'|window.tokenapiUrl = '$FLOAPIURL'|" /floscout/index.html
echo "Running Floscout"
supervisord -c /etc/supervisor/conf.d/ftt-ranchimallflo.conf