mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-11-22 15:20:09 +01:00
Merge branch 'pr/93' into Migrate-to-SQLite
This commit is contained in:
commit
75f2826805
4
src/certbot.ini
Normal file
4
src/certbot.ini
Normal file
@ -0,0 +1,4 @@
|
||||
authenticator = standalone
|
||||
noninteractive = true
|
||||
agree-tos = true
|
||||
rsa-key-size = 2048
|
@ -1670,13 +1670,37 @@ def check_update():
|
||||
|
||||
return result
|
||||
|
||||
"""
|
||||
Configure DashBoard before start web-server
|
||||
"""
|
||||
def run_dashboard():
|
||||
init_dashboard()
|
||||
global update
|
||||
update = check_update()
|
||||
global config
|
||||
config = configparser.ConfigParser(strict=False)
|
||||
config.read('wg-dashboard.ini')
|
||||
global app_ip
|
||||
app_ip = config.get("Server", "app_ip")
|
||||
global app_port
|
||||
app_port = config.get("Server", "app_port")
|
||||
global wg_conf_path
|
||||
wg_conf_path = config.get("Server", "wg_conf_path")
|
||||
config.clear()
|
||||
return app
|
||||
|
||||
"""
|
||||
Get host and port for web-server
|
||||
"""
|
||||
def get_host_bind():
|
||||
init_dashboard()
|
||||
config = configparser.ConfigParser(strict=False)
|
||||
config.read('wg-dashboard.ini')
|
||||
app_ip = config.get("Server", "app_ip")
|
||||
app_port = config.get("Server", "app_port")
|
||||
|
||||
return app_ip, app_port
|
||||
|
||||
if __name__ == "__main__":
|
||||
init_dashboard()
|
||||
UPDATE = check_update()
|
||||
configuration_settings = get_dashboard_conf()
|
||||
app_ip = configuration_settings.get("Server", "app_ip")
|
||||
app_port = int(configuration_settings.get("Server", "app_port"))
|
||||
WG_CONF_PATH = configuration_settings.get("Server", "wg_conf_path")
|
||||
configuration_settings.clear()
|
||||
run_dashboard()
|
||||
app.run(host=app_ip, debug=False, port=app_port)
|
||||
|
11
src/gunicorn.conf.py
Normal file
11
src/gunicorn.conf.py
Normal file
@ -0,0 +1,11 @@
|
||||
import multiprocessing
|
||||
import dashboard
|
||||
|
||||
app_host, app_port = dashboard.get_host_bind()
|
||||
|
||||
worker_class = 'gthread'
|
||||
workers = multiprocessing.cpu_count() * 2 + 1
|
||||
threads = 4
|
||||
bind = f"{app_host}:{app_port}"
|
||||
daemon = True
|
||||
pidfile = './gunicorn.pid'
|
@ -3,3 +3,5 @@ tinydb==4.5.2
|
||||
ifcfg
|
||||
icmplib
|
||||
flask-qrcode
|
||||
gunicorn
|
||||
certbot
|
94
src/wgd.sh
94
src/wgd.sh
@ -4,6 +4,15 @@
|
||||
# Under Apache-2.0 License
|
||||
app_name="dashboard.py"
|
||||
app_official_name="WGDashboard"
|
||||
environment=$(if [[ $ENVIRONMENT ]]; then echo $ENVIRONMENT; else echo 'develop'; fi)
|
||||
if [[ $CONFIGURATION_PATH ]]; then
|
||||
cb_work_dir=$CONFIGURATION_PATH/letsencrypt/work-dir
|
||||
cb_config_dir=$CONFIGURATION_PATH/letsencrypt/config-dir
|
||||
else
|
||||
cb_work_dir=/etc/letsencrypt
|
||||
cb_config_dir=/var/lib/letsencrypt
|
||||
fi
|
||||
|
||||
dashes='------------------------------------------------------------'
|
||||
equals='============================================================'
|
||||
help () {
|
||||
@ -57,28 +66,85 @@ install_wgd(){
|
||||
|
||||
|
||||
check_wgd_status(){
|
||||
if ps aux | grep '[p]ython3 '$app_name > /dev/null;
|
||||
then
|
||||
if [[ $environment == 'production' ]]; then
|
||||
if ps aux | grep -v grep | grep $(cat ./gunicorn.pid) > /dev/null; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
if ps aux | grep -v grep | grep '[p]ython3 '$app_name > /dev/null; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
start_wgd () {
|
||||
printf "%s\n" "$dashes"
|
||||
printf "| Starting WGDashboard in the background. |\n"
|
||||
if [ ! -d "log" ]
|
||||
then mkdir "log"
|
||||
certbot_create_ssl () {
|
||||
certbot certonly --config ./certbot.ini --email "$EMAIL" --work-dir $cb_work_dir --config-dir $cb_config_dir --domain "$SERVERURL"
|
||||
}
|
||||
|
||||
certbot_renew_ssl () {
|
||||
certbot renew --work-dir $cb_work_dir --config-dir $cb_config_dir
|
||||
}
|
||||
|
||||
gunicorn_start () {
|
||||
if [[ $SSL ]]; then
|
||||
if [ ! -d $cb_config_dir ]; then
|
||||
certbot_create_ssl
|
||||
else
|
||||
certbot_renew_ssl
|
||||
fi
|
||||
fi
|
||||
printf "%s\n" "$dashes"
|
||||
printf "| Starting WGDashboard in the background. |\n"
|
||||
if [ ! -d "log" ]; then
|
||||
mkdir "log"
|
||||
fi
|
||||
d=$(date '+%Y%m%d%H%M%S')
|
||||
if [[ $USER == root ]]; then
|
||||
export PATH=$PATH:/usr/local/bin:$HOME/.local/bin
|
||||
fi
|
||||
if [[ $SSL ]]; then
|
||||
gunicorn --certfile $cb_config_dir/live/"$SERVERURL"/cert.pem \
|
||||
--keyfile $cb_config_dir/live/"$SERVERURL"/privkey.pem \
|
||||
--access-logfile log/access_"$d".log \
|
||||
--error-logfile log/error_"$d".log 'dashboard:run_dashboard()'
|
||||
else
|
||||
gunicorn --access-logfile log/access_"$d".log \
|
||||
--error-logfile log/error_"$d".log 'dashboard:run_dashboard()'
|
||||
fi
|
||||
printf "| Log files is under log/ |\n"
|
||||
printf "%s\n" "$dashes"
|
||||
}
|
||||
|
||||
gunicorn_stop () {
|
||||
kill $(cat ./gunicorn.pid)
|
||||
}
|
||||
|
||||
start_wgd () {
|
||||
if [[ $environment == 'production' ]]; then
|
||||
gunicorn_start
|
||||
else
|
||||
printf "%s\n" "$dashes"
|
||||
printf "| Starting WGDashboard in the background. |\n"
|
||||
if [ ! -d "log" ]
|
||||
then mkdir "log"
|
||||
fi
|
||||
d=$(date '+%Y%m%d%H%M%S')
|
||||
python3 "$app_name" > log/"$d".txt 2>&1 &
|
||||
printf "| Log files is under log/ |\n"
|
||||
printf "%s\n" "$dashes"
|
||||
fi
|
||||
d=$(date '+%Y%m%d%H%M%S')
|
||||
python3 "$app_name" > log/"$d".txt 2>&1 &
|
||||
printf "| Log files is under log/ |\n"
|
||||
printf "%s\n" "$dashes"
|
||||
}
|
||||
|
||||
stop_wgd() {
|
||||
kill "$(ps aux | grep "[p]ython3 $app_name" | awk '{print $2}')"
|
||||
if [[ $environment == 'production' ]]; then
|
||||
gunicorn_stop
|
||||
else
|
||||
kill "$(ps aux | grep "[p]ython3 $app_name" | awk '{print $2}')"
|
||||
fi
|
||||
}
|
||||
|
||||
start_wgd_debug() {
|
||||
|
Loading…
Reference in New Issue
Block a user